src/video/directfb/SDL_DirectFB_video.c
author Bob Pendleton <bob@pendleton.com>
Fri, 09 Jan 2009 20:43:30 +0000
changeset 3011 8f4ed5ec2b06
parent 2998 d364ee9b9c15
child 3013 8cc00819c8d6
permissions -rw-r--r--
I ran a global "make indent" it modified the following files.
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>
slouken@167
    38
slouken@167
    39
#include "SDL_video.h"
slouken@167
    40
#include "SDL_mouse.h"
slouken@1361
    41
#include "../SDL_sysvideo.h"
slouken@1361
    42
#include "../SDL_pixels_c.h"
slouken@1361
    43
#include "../../events/SDL_events_c.h"
slouken@167
    44
#include "SDL_DirectFB_video.h"
slouken@167
    45
#include "SDL_DirectFB_events.h"
slouken@2737
    46
#include "SDL_DirectFB_render.h"
slouken@2737
    47
#include "SDL_DirectFB_mouse.h"
slouken@167
    48
slouken@2998
    49
#include "SDL_DirectFB_dyn.h"
slouken@2998
    50
slouken@2226
    51
/* Initialization/Query functions */
slouken@2226
    52
static int DirectFB_VideoInit(_THIS);
slouken@2226
    53
static void DirectFB_VideoQuit(_THIS);
slouken@2226
    54
slouken@2737
    55
static int DirectFB_Available(void);
slouken@2737
    56
static SDL_VideoDevice *DirectFB_CreateDevice(int devindex);
slouken@2226
    57
slouken@2226
    58
static int DirectFB_SetDisplayGammaRamp(_THIS, Uint16 * ramp);
slouken@2226
    59
static int DirectFB_GetDisplayGammaRamp(_THIS, Uint16 * ramp);
slouken@2226
    60
slouken@2737
    61
VideoBootStrap DirectFB_bootstrap = {
slouken@2737
    62
    "directfb", "DirectFB",
slouken@2737
    63
    DirectFB_Available, DirectFB_CreateDevice
slouken@2737
    64
};
slouken@167
    65
slouken@167
    66
/* DirectFB driver bootstrap functions */
slouken@167
    67
slouken@1895
    68
static int
slouken@1895
    69
DirectFB_Available(void)
slouken@167
    70
{
slouken@2998
    71
    if (!SDL_DirectFB_LoadLibrary())
slouken@2998
    72
        return 0;
slouken@2998
    73
    SDL_DirectFB_UnLoadLibrary();
slouken@1895
    74
    return 1;
slouken@167
    75
}
slouken@167
    76
slouken@1895
    77
static void
slouken@1895
    78
DirectFB_DeleteDevice(SDL_VideoDevice * device)
slouken@167
    79
{
slouken@2998
    80
    SDL_DirectFB_UnLoadLibrary();
slouken@2998
    81
    SDL_DFB_FREE(device->driverdata);
slouken@2998
    82
    SDL_DFB_FREE(device);
slouken@167
    83
}
slouken@167
    84
slouken@1895
    85
static SDL_VideoDevice *
slouken@1895
    86
DirectFB_CreateDevice(int devindex)
slouken@167
    87
{
slouken@1895
    88
    SDL_VideoDevice *device;
slouken@167
    89
slouken@2998
    90
    if (!SDL_DirectFB_LoadLibrary())
slouken@2998
    91
        return NULL;
slouken@2998
    92
slouken@1895
    93
    /* Initialize all variables that we clean on shutdown */
slouken@2226
    94
    SDL_DFB_CALLOC(device, 1, sizeof(SDL_VideoDevice));
slouken@2226
    95
slouken@2226
    96
    /* Set the function pointers */
slouken@167
    97
slouken@1895
    98
    /* Set the function pointers */
slouken@1895
    99
    device->VideoInit = DirectFB_VideoInit;
slouken@1895
   100
    device->VideoQuit = DirectFB_VideoQuit;
slouken@2226
   101
    device->GetDisplayModes = DirectFB_GetDisplayModes;
slouken@2226
   102
    device->SetDisplayMode = DirectFB_SetDisplayMode;
slouken@2226
   103
#if 0
slouken@2226
   104
    device->SetDisplayGammaRamp = DirectFB_SetDisplayGammaRamp;
slouken@2226
   105
    device->GetDisplayGammaRamp = DirectFB_GetDisplayGammaRamp;
slouken@2226
   106
#else
slouken@2226
   107
    device->SetDisplayGammaRamp = NULL;
slouken@2226
   108
    device->GetDisplayGammaRamp = NULL;
slouken@2226
   109
#endif
slouken@2226
   110
    device->PumpEvents = DirectFB_PumpEventsWindow;
slouken@2226
   111
    device->CreateWindow = DirectFB_CreateWindow;
slouken@2226
   112
    device->CreateWindowFrom = DirectFB_CreateWindowFrom;
slouken@2226
   113
    device->SetWindowTitle = DirectFB_SetWindowTitle;
slouken@2226
   114
    device->SetWindowPosition = DirectFB_SetWindowPosition;
slouken@2226
   115
    device->SetWindowSize = DirectFB_SetWindowSize;
slouken@2226
   116
    device->ShowWindow = DirectFB_ShowWindow;
slouken@2226
   117
    device->HideWindow = DirectFB_HideWindow;
slouken@2226
   118
    device->RaiseWindow = DirectFB_RaiseWindow;
slouken@2226
   119
    device->MaximizeWindow = DirectFB_MaximizeWindow;
slouken@2226
   120
    device->MinimizeWindow = DirectFB_MinimizeWindow;
slouken@2226
   121
    device->RestoreWindow = DirectFB_RestoreWindow;
slouken@2226
   122
    device->SetWindowGrab = DirectFB_SetWindowGrab;
slouken@2226
   123
    device->DestroyWindow = DirectFB_DestroyWindow;
slouken@2226
   124
    device->GetWindowWMInfo = DirectFB_GetWindowWMInfo;
slouken@2226
   125
slouken@2226
   126
#if SDL_DIRECTFB_OPENGL
slouken@2226
   127
    device->GL_LoadLibrary = DirectFB_GL_LoadLibrary;
slouken@2226
   128
    device->GL_GetProcAddress = DirectFB_GL_GetProcAddress;
slouken@2226
   129
    device->GL_MakeCurrent = DirectFB_GL_MakeCurrent;
slouken@2226
   130
slouken@2226
   131
    device->GL_CreateContext = DirectFB_GL_CreateContext;
slouken@2226
   132
    device->GL_SetSwapInterval = DirectFB_GL_SetSwapInterval;
slouken@2226
   133
    device->GL_GetSwapInterval = DirectFB_GL_GetSwapInterval;
slouken@2226
   134
    device->GL_SwapWindow = DirectFB_GL_SwapWindow;
slouken@2226
   135
    device->GL_DeleteContext = DirectFB_GL_DeleteContext;
slouken@2226
   136
slouken@2226
   137
#endif
slouken@167
   138
slouken@1895
   139
    device->free = DirectFB_DeleteDevice;
slouken@167
   140
slouken@1895
   141
    return device;
slouken@2226
   142
  error:
slouken@2226
   143
    if (device)
slouken@2226
   144
        free(device);
slouken@2226
   145
    return (0);
slouken@167
   146
}
slouken@167
   147
slouken@1895
   148
static int
slouken@2226
   149
DirectFB_VideoInit(_THIS)
slouken@1895
   150
{
slouken@1895
   151
    IDirectFB *dfb = NULL;
slouken@2998
   152
    DFB_DeviceData *devdata = NULL;
slouken@2737
   153
    char *stemp;
slouken@2226
   154
    DFBResult ret;
slouken@1895
   155
slouken@2998
   156
    SDL_DFB_CALLOC(devdata, 1, sizeof(*devdata));
slouken@2998
   157
slouken@2226
   158
    SDL_DFB_CHECKERR(DirectFBInit(NULL, NULL));
slouken@2998
   159
slouken@2998
   160
    /* avoid switching to the framebuffer when we
slouken@2998
   161
     * are running X11 */
slouken@2998
   162
    stemp = getenv(DFBENV_USE_X11_CHECK);
slouken@2998
   163
    if (stemp)
slouken@2998
   164
        ret = atoi(stemp);
slouken@2998
   165
    else
slouken@2998
   166
        ret = 1;
slouken@2998
   167
slouken@2998
   168
    if (ret) {
slouken@2998
   169
        if (getenv("DISPLAY"))
slouken@2998
   170
            DirectFBSetOption("system", "x11");
slouken@2998
   171
        else
slouken@2998
   172
            DirectFBSetOption("disable-module", "x11input");
slouken@2998
   173
    }
slouken@2998
   174
slouken@2998
   175
    devdata->use_linux_input = 1;       /* default: on */
slouken@2998
   176
    stemp = getenv(DFBENV_USE_LINUX_INPUT);
slouken@2998
   177
    if (stemp)
slouken@2998
   178
        devdata->use_linux_input = atoi(stemp);
slouken@2998
   179
slouken@2998
   180
    if (!devdata->use_linux_input)
slouken@2998
   181
        DirectFBSetOption("disable-module", "linux_input");
slouken@2998
   182
slouken@2226
   183
    SDL_DFB_CHECKERR(DirectFBCreate(&dfb));
slouken@2226
   184
slouken@2737
   185
    devdata->use_yuv_underlays = 0;     /* default: off */
slouken@2737
   186
    stemp = getenv(DFBENV_USE_YUV_UNDERLAY);
slouken@2737
   187
    if (stemp)
slouken@2737
   188
        devdata->use_yuv_underlays = atoi(stemp);
slouken@2226
   189
slouken@2998
   190
slouken@2737
   191
    /* Create global Eventbuffer for axis events */
slouken@2998
   192
    if (devdata->use_linux_input) {
bob@3011
   193
        SDL_DFB_CHECKERR(dfb->CreateInputEventBuffer(dfb, DICAPS_ALL,
bob@3011
   194
                                                     DFB_TRUE,
bob@3011
   195
                                                     &devdata->events));
slouken@2860
   196
    } else {
bob@3011
   197
        SDL_DFB_CHECKERR(dfb->CreateInputEventBuffer(dfb,
bob@3011
   198
                                                     DICAPS_AXES
bob@3011
   199
                                                     /*DICAPS_ALL */ ,
bob@3011
   200
                                                     DFB_TRUE,
bob@3011
   201
                                                     &devdata->events));
slouken@2860
   202
    }
slouken@1895
   203
slouken@2226
   204
    devdata->initialized = 1;
slouken@2226
   205
    devdata->dfb = dfb;
slouken@2226
   206
    devdata->firstwin = NULL;
slouken@2226
   207
slouken@2226
   208
    _this->driverdata = devdata;
slouken@2226
   209
slouken@2737
   210
    DirectFB_InitModes(_this);
slouken@2226
   211
slouken@2226
   212
#if SDL_DIRECTFB_OPENGL
slouken@2737
   213
    DirectFB_GL_Initialize(_this);
slouken@2226
   214
#endif
slouken@2226
   215
slouken@2226
   216
    DirectFB_AddRenderDriver(_this);
slouken@2226
   217
    DirectFB_InitMouse(_this);
slouken@2721
   218
    DirectFB_InitKeyboard(_this);
slouken@2737
   219
slouken@2226
   220
slouken@2226
   221
    return 0;
slouken@2226
   222
slouken@2226
   223
slouken@2226
   224
  error:
slouken@2998
   225
    SDL_DFB_FREE(devdata);
slouken@2226
   226
    SDL_DFB_RELEASE(dfb);
slouken@2226
   227
    return -1;
slouken@2226
   228
}
slouken@2226
   229
slouken@2226
   230
static void
slouken@2226
   231
DirectFB_VideoQuit(_THIS)
slouken@2226
   232
{
slouken@2226
   233
    DFB_DeviceData *devdata = (DFB_DeviceData *) _this->driverdata;
slouken@2226
   234
slouken@2737
   235
    DirectFB_QuitModes(_this);
slouken@2737
   236
    DirectFB_QuitKeyboard(_this);
slouken@2737
   237
    DirectFB_QuitMouse(_this);
slouken@2226
   238
slouken@2737
   239
    SDL_DFB_RELEASE(devdata->events);
slouken@2226
   240
    SDL_DFB_RELEASE(devdata->dfb);
slouken@1895
   241
slouken@2226
   242
#if SDL_DIRECTFB_OPENGL
slouken@2737
   243
    DirectFB_GL_Shutdown(_this);
slouken@1895
   244
#endif
slouken@1895
   245
slouken@2226
   246
    devdata->initialized = 0;
slouken@2226
   247
}
slouken@1895
   248
slouken@2226
   249
static int
slouken@2226
   250
DirectFB_SetDisplayGammaRamp(_THIS, Uint16 * ramp)
slouken@1895
   251
{
slouken@2226
   252
    return -1;
slouken@1895
   253
}
slouken@1895
   254
slouken@2226
   255
static int
slouken@2226
   256
DirectFB_GetDisplayGammaRamp(_THIS, Uint16 * ramp)
slouken@1895
   257
{
slouken@2226
   258
    return -1;
slouken@2226
   259
}