src/video/directfb/SDL_DirectFB_video.c
author Sam Lantinga
Sun, 31 Aug 2008 16:04:32 +0000
changeset 2737 140a7edcf2bd
parent 2735 204be4fc2726
child 2859 99210400e8b9
permissions -rw-r--r--
Date: Sun, 31 Aug 2008 17:53:59 +0200
From: Couriersud
Subject: Re: Updated DirectFB driver for SDL1.3

attached is a patch which brings the directfb driver in line with
current svn. In addition:

* driver now is in line with the structure of the X11 driver.
This adds a couple of files.
* driver now supports relative mouse movements
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
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@2226
    48
slouken@2226
    49
/* Initialization/Query functions */
slouken@2226
    50
static int DirectFB_VideoInit(_THIS);
slouken@2226
    51
static void DirectFB_VideoQuit(_THIS);
slouken@167
    52
slouken@2737
    53
static int DirectFB_Available(void);
slouken@2737
    54
static SDL_VideoDevice *DirectFB_CreateDevice(int devindex);
slouken@2226
    55
slouken@2226
    56
static int DirectFB_SetDisplayGammaRamp(_THIS, Uint16 * ramp);
slouken@2226
    57
static int DirectFB_GetDisplayGammaRamp(_THIS, Uint16 * ramp);
slouken@2226
    58
slouken@2737
    59
VideoBootStrap DirectFB_bootstrap = {
slouken@2737
    60
    "directfb", "DirectFB",
slouken@2737
    61
    DirectFB_Available, DirectFB_CreateDevice
slouken@2737
    62
};
slouken@167
    63
slouken@167
    64
/* DirectFB driver bootstrap functions */
slouken@167
    65
slouken@1895
    66
static int
slouken@1895
    67
DirectFB_Available(void)
slouken@167
    68
{
slouken@1895
    69
    return 1;
slouken@167
    70
}
slouken@167
    71
slouken@1895
    72
static void
slouken@1895
    73
DirectFB_DeleteDevice(SDL_VideoDevice * device)
slouken@167
    74
{
slouken@2226
    75
    SDL_free(device->driverdata);
slouken@1895
    76
    SDL_free(device);
slouken@167
    77
}
slouken@167
    78
slouken@1895
    79
static SDL_VideoDevice *
slouken@1895
    80
DirectFB_CreateDevice(int devindex)
slouken@167
    81
{
slouken@1895
    82
    SDL_VideoDevice *device;
slouken@167
    83
slouken@1895
    84
    /* Initialize all variables that we clean on shutdown */
slouken@2226
    85
    SDL_DFB_CALLOC(device, 1, sizeof(SDL_VideoDevice));
slouken@2226
    86
slouken@2226
    87
    /* Set the function pointers */
slouken@167
    88
slouken@1895
    89
    /* Set the function pointers */
slouken@1895
    90
    device->VideoInit = DirectFB_VideoInit;
slouken@1895
    91
    device->VideoQuit = DirectFB_VideoQuit;
slouken@2226
    92
    device->GetDisplayModes = DirectFB_GetDisplayModes;
slouken@2226
    93
    device->SetDisplayMode = DirectFB_SetDisplayMode;
slouken@2226
    94
#if 0
slouken@2226
    95
    device->SetDisplayGammaRamp = DirectFB_SetDisplayGammaRamp;
slouken@2226
    96
    device->GetDisplayGammaRamp = DirectFB_GetDisplayGammaRamp;
slouken@2226
    97
#else
slouken@2226
    98
    device->SetDisplayGammaRamp = NULL;
slouken@2226
    99
    device->GetDisplayGammaRamp = NULL;
slouken@2226
   100
#endif
slouken@2226
   101
    device->PumpEvents = DirectFB_PumpEventsWindow;
slouken@2226
   102
    device->CreateWindow = DirectFB_CreateWindow;
slouken@2226
   103
    device->CreateWindowFrom = DirectFB_CreateWindowFrom;
slouken@2226
   104
    device->SetWindowTitle = DirectFB_SetWindowTitle;
slouken@2226
   105
    device->SetWindowPosition = DirectFB_SetWindowPosition;
slouken@2226
   106
    device->SetWindowSize = DirectFB_SetWindowSize;
slouken@2226
   107
    device->ShowWindow = DirectFB_ShowWindow;
slouken@2226
   108
    device->HideWindow = DirectFB_HideWindow;
slouken@2226
   109
    device->RaiseWindow = DirectFB_RaiseWindow;
slouken@2226
   110
    device->MaximizeWindow = DirectFB_MaximizeWindow;
slouken@2226
   111
    device->MinimizeWindow = DirectFB_MinimizeWindow;
slouken@2226
   112
    device->RestoreWindow = DirectFB_RestoreWindow;
slouken@2226
   113
    device->SetWindowGrab = DirectFB_SetWindowGrab;
slouken@2226
   114
    device->DestroyWindow = DirectFB_DestroyWindow;
slouken@2226
   115
    device->GetWindowWMInfo = DirectFB_GetWindowWMInfo;
slouken@2226
   116
slouken@2226
   117
#if SDL_DIRECTFB_OPENGL
slouken@2226
   118
    device->GL_LoadLibrary = DirectFB_GL_LoadLibrary;
slouken@2226
   119
    device->GL_GetProcAddress = DirectFB_GL_GetProcAddress;
slouken@2226
   120
    device->GL_MakeCurrent = DirectFB_GL_MakeCurrent;
slouken@2226
   121
slouken@2226
   122
    device->GL_CreateContext = DirectFB_GL_CreateContext;
slouken@2226
   123
    device->GL_SetSwapInterval = DirectFB_GL_SetSwapInterval;
slouken@2226
   124
    device->GL_GetSwapInterval = DirectFB_GL_GetSwapInterval;
slouken@2226
   125
    device->GL_SwapWindow = DirectFB_GL_SwapWindow;
slouken@2226
   126
    device->GL_DeleteContext = DirectFB_GL_DeleteContext;
slouken@2226
   127
slouken@2226
   128
#endif
slouken@167
   129
slouken@1895
   130
    device->free = DirectFB_DeleteDevice;
slouken@167
   131
slouken@1895
   132
    return device;
slouken@2226
   133
  error:
slouken@2226
   134
    if (device)
slouken@2226
   135
        free(device);
slouken@2226
   136
    return (0);
slouken@167
   137
}
slouken@167
   138
slouken@1895
   139
static int
slouken@2226
   140
DirectFB_VideoInit(_THIS)
slouken@167
   141
{
slouken@1895
   142
    IDirectFB *dfb = NULL;
slouken@2226
   143
    DFB_DeviceData *devdata;
slouken@2737
   144
    char *stemp;
slouken@2226
   145
    DFBResult ret;
slouken@2226
   146
slouken@2226
   147
    SDL_DFB_CHECKERR(DirectFBInit(NULL, NULL));
slouken@2226
   148
    SDL_DFB_CHECKERR(DirectFBCreate(&dfb));
slouken@167
   149
slouken@2226
   150
    SDL_DFB_CALLOC(devdata, 1, sizeof(*devdata));
slouken@2226
   151
slouken@2737
   152
    devdata->use_yuv_underlays = 0;     /* default: off */
slouken@2737
   153
    stemp = getenv(DFBENV_USE_YUV_UNDERLAY);
slouken@2737
   154
    if (stemp)
slouken@2737
   155
        devdata->use_yuv_underlays = atoi(stemp);
slouken@2226
   156
slouken@2737
   157
    /* Create global Eventbuffer for axis events */
slouken@2737
   158
    SDL_DFB_CHECKERR(dfb->
slouken@2737
   159
                     CreateInputEventBuffer(dfb, DICAPS_AXES /*DICAPS_ALL */ ,
slouken@2737
   160
                                            DFB_TRUE, &devdata->events));
slouken@167
   161
slouken@2226
   162
    devdata->initialized = 1;
slouken@2226
   163
    devdata->dfb = dfb;
slouken@2226
   164
    devdata->firstwin = NULL;
slouken@464
   165
slouken@2226
   166
    _this->driverdata = devdata;
slouken@464
   167
slouken@2737
   168
    DirectFB_InitModes(_this);
slouken@464
   169
slouken@2226
   170
#if SDL_DIRECTFB_OPENGL
slouken@2737
   171
    DirectFB_GL_Initialize(_this);
icculus@1165
   172
#endif
slouken@167
   173
slouken@2226
   174
    DirectFB_AddRenderDriver(_this);
slouken@2226
   175
    DirectFB_InitMouse(_this);
slouken@2721
   176
    DirectFB_InitKeyboard(_this);
slouken@2737
   177
slouken@2226
   178
slouken@2226
   179
    return 0;
slouken@2226
   180
slouken@167
   181
slouken@2226
   182
  error:
slouken@2226
   183
    SDL_DFB_RELEASE(dfb);
slouken@2226
   184
    return -1;
slouken@2226
   185
}
slouken@1895
   186
slouken@2226
   187
static void
slouken@2226
   188
DirectFB_VideoQuit(_THIS)
slouken@2226
   189
{
slouken@2226
   190
    DFB_DeviceData *devdata = (DFB_DeviceData *) _this->driverdata;
slouken@1895
   191
slouken@2737
   192
    DirectFB_QuitModes(_this);
slouken@2737
   193
    DirectFB_QuitKeyboard(_this);
slouken@2737
   194
    DirectFB_QuitMouse(_this);
icculus@728
   195
slouken@2737
   196
    SDL_DFB_RELEASE(devdata->events);
slouken@2226
   197
    SDL_DFB_RELEASE(devdata->dfb);
slouken@2737
   198
    SDL_DFB_FREE(_this->driverdata);
icculus@728
   199
slouken@2226
   200
#if SDL_DIRECTFB_OPENGL
slouken@2737
   201
    DirectFB_GL_Shutdown(_this);
slouken@2226
   202
#endif
slouken@2226
   203
slouken@2226
   204
    devdata->initialized = 0;
slouken@2226
   205
}
slouken@2226
   206
slouken@2226
   207
static int
slouken@2226
   208
DirectFB_SetDisplayGammaRamp(_THIS, Uint16 * ramp)
slouken@2226
   209
{
slouken@1895
   210
    return -1;
slouken@167
   211
}
slouken@167
   212
slouken@2226
   213
static int
slouken@2226
   214
DirectFB_GetDisplayGammaRamp(_THIS, Uint16 * ramp)
slouken@2226
   215
{
slouken@2226
   216
    return -1;
slouken@2226
   217
}