src/video/directfb/SDL_DirectFB_video.h
author Sam Lantinga <slouken@libsdl.org>
Sat, 11 Aug 2007 21:51:19 +0000
changeset 2226 0e70b4b8cf84
parent 1895 c121d94672cb
child 2721 e82a0e3e9b0e
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@167
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@167
     4
slouken@167
     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@167
     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@167
    10
    This library is distributed in the hope that it will be useful,
slouken@167
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@167
    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@167
    19
    Sam Lantinga
slouken@252
    20
    slouken@libsdl.org
slouken@167
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@167
    23
slouken@167
    24
#ifndef _SDL_DirectFB_video_h
slouken@167
    25
#define _SDL_DirectFB_video_h
slouken@167
    26
slouken@167
    27
#include <directfb.h>
slouken@2226
    28
#include <directfb_version.h>
slouken@2226
    29
slouken@2226
    30
#define LOG_CHANNEL 	stdout
slouken@2226
    31
slouken@2226
    32
#if (DIRECTFB_MAJOR_VERSION == 0) && (DIRECTFB_MINOR_VERSION == 9) && (DIRECTFB_MICRO_VERSION < 23)
slouken@2226
    33
#error "SDL_DIRECTFB: Please compile against libdirectfb version >=0.9.24"
slouken@2226
    34
#endif
slouken@2226
    35
slouken@2226
    36
#if (DIRECTFB_MAJOR_VERSION >= 1) && (DIRECTFB_MINOR_VERSION >= 0) && (DIRECTFB_MICRO_VERSION >= 0 )
slouken@2226
    37
#define SDL_DIRECTFB_OPENGL 1
slouken@2226
    38
#include <directfbgl.h>
slouken@2226
    39
#endif
slouken@2226
    40
slouken@2226
    41
#if SDL_DIRECTFB_OPENGL
slouken@2226
    42
#include "SDL_loadso.h"
slouken@2226
    43
#endif
slouken@167
    44
slouken@167
    45
#include "SDL_mouse.h"
slouken@1361
    46
#include "../SDL_sysvideo.h"
slouken@167
    47
slouken@2226
    48
#define DEBUG 1
slouken@2226
    49
slouken@2226
    50
#define SDL_DFB_RELEASE(x) do { if ( x ) { x->Release(x); x = NULL; } } while (0)
slouken@2226
    51
#define SDL_DFB_FREE(x) do { if ( x ) { SDL_free(x); x = NULL; } } while (0)
slouken@2226
    52
#define SDL_DFB_UNLOCK(x) do { if ( x ) { x->Unlock(x); } } while (0)
slouken@2226
    53
slouken@2226
    54
#if DEBUG
slouken@2226
    55
#define SDL_DFB_DEBUG(x...) do { fprintf(LOG_CHANNEL, "%s:", __FUNCTION__); fprintf(LOG_CHANNEL, x); } while (0)
slouken@2226
    56
#define SDL_DFB_DEBUGC(x...) do { fprintf(LOG_CHANNEL, x); } while (0)
slouken@2226
    57
#else
slouken@2226
    58
#define SDL_DFB_DEBUG(x...) do { } while (0)
slouken@2226
    59
#define SDL_DFB_DEBUGC(x...) do { } while (0)
slouken@2226
    60
#endif
slouken@2226
    61
slouken@2226
    62
#define SDL_DFB_CONTEXT "SDL_DirectFB"
slouken@2226
    63
slouken@2226
    64
#define SDL_DFB_ERR(x...) 							\
slouken@2226
    65
	do {											\
slouken@2226
    66
		fprintf(LOG_CHANNEL, "%s: %s <%d>:\n\t",			\
slouken@2226
    67
			SDL_DFB_CONTEXT, __FILE__, __LINE__ );	\
slouken@2226
    68
		fprintf(LOG_CHANNEL, x );						\
slouken@2226
    69
	} while (0)
slouken@2226
    70
slouken@2226
    71
#define SDL_DFB_CHECK(x...) \
slouken@2226
    72
     do {                                                                \
slouken@2226
    73
          ret = x;                                                    \
slouken@2226
    74
          if (ret != DFB_OK) {                                        \
slouken@2226
    75
               fprintf(LOG_CHANNEL, "%s <%d>:\n\t", __FILE__, __LINE__ ); 	      \
slouken@2226
    76
               SDL_SetError( #x, DirectFBErrorString (ret) );         \
slouken@2226
    77
          }                                                           \
slouken@2226
    78
     } while (0)
slouken@2226
    79
slouken@2226
    80
#define SDL_DFB_CHECKERR(x...) \
slouken@2226
    81
     do {                                                                \
slouken@2226
    82
          ret = x;                                                    \
slouken@2226
    83
          if (ret != DFB_OK) {                                        \
slouken@2226
    84
               fprintf(LOG_CHANNEL, "%s <%d>:\n", __FILE__, __LINE__ ); \
slouken@2226
    85
               fprintf(LOG_CHANNEL, "\t%s\n", #x ); \
slouken@2226
    86
               fprintf(LOG_CHANNEL, "\t%s\n", DirectFBErrorString (ret) ); \
slouken@2226
    87
               SDL_SetError( #x, DirectFBErrorString (ret) );         \
slouken@2226
    88
               goto error; 					      \
slouken@2226
    89
          }                                                           \
slouken@2226
    90
     } while (0)
slouken@2226
    91
slouken@2226
    92
#define SDL_DFB_CALLOC(r, n, s) \
slouken@2226
    93
     do {                                                                \
slouken@2226
    94
          r = SDL_calloc (n, s);                                      \
slouken@2226
    95
          if (!(r)) {                                                 \
slouken@2226
    96
               fprintf( LOG_CHANNEL, "%s <%d>:\n\t", __FILE__, __LINE__ ); \
slouken@2226
    97
               SDL_OutOfMemory();                                     \
slouken@2226
    98
               goto error; 					      \
slouken@2226
    99
          }                                                           \
slouken@2226
   100
     } while (0)
slouken@167
   101
slouken@167
   102
/* Private display data */
slouken@167
   103
slouken@2226
   104
#define SDL_DFB_DEVICEDATA(dev)  DFB_DeviceData *devdata = (DFB_DeviceData *) ((dev)->driverdata)
slouken@2226
   105
#define SDL_DFB_WINDOWDATA(win)  DFB_WindowData *windata = ((win) ? (DFB_WindowData *) ((win)->driverdata) : NULL)
slouken@2226
   106
#define SDL_DFB_DISPLAYDATA(dev, win)  DFB_DisplayData *dispdata = ((win && dev) ? (DFB_DisplayData *) (dev)->displays[(win)->display].driverdata : NULL)
slouken@2226
   107
slouken@2226
   108
typedef struct _DFB_DisplayData DFB_DisplayData;
slouken@2226
   109
slouken@2226
   110
#define DFB_MAX_SCREENS 10
slouken@2226
   111
#define DFB_MAX_MODES 50
slouken@2226
   112
slouken@2226
   113
struct _DFB_DisplayData
slouken@2226
   114
{
slouken@2226
   115
    IDirectFBDisplayLayer *layer;
slouken@2226
   116
    DFBSurfacePixelFormat pixelformat;
slouken@2226
   117
    DFBDisplayLayerID vidID;
slouken@2226
   118
slouken@2226
   119
    int cw;
slouken@2226
   120
    int ch;
slouken@2226
   121
slouken@2226
   122
    int nummodes;
slouken@2226
   123
    SDL_DisplayMode *modelist;
slouken@2226
   124
slouken@2226
   125
#if 0
slouken@2226
   126
    WMcursor *last_cursor;
slouken@2226
   127
    WMcursor *blank_cursor;
slouken@2226
   128
    WMcursor *default_cursor;
slouken@2226
   129
#endif
slouken@2226
   130
};
slouken@2226
   131
slouken@2226
   132
slouken@2226
   133
typedef struct _DFB_WindowData DFB_WindowData;
slouken@2226
   134
struct _DFB_WindowData
slouken@2226
   135
{
slouken@2226
   136
    IDirectFBSurface *surface;
slouken@2226
   137
    IDirectFBPalette *palette;
slouken@2226
   138
    IDirectFBWindow *window;
slouken@2226
   139
    IDirectFBGL *gl_context;
slouken@2226
   140
    IDirectFBEventBuffer *eventbuffer;
slouken@2226
   141
    DFBWindowID windowID;
slouken@2226
   142
    int id;                     // SDL window id
slouken@2226
   143
    DFB_WindowData *next;
slouken@2226
   144
    u8 opacity;
slouken@2226
   145
};
slouken@2226
   146
slouken@2226
   147
typedef struct _DFB_DeviceData DFB_DeviceData;
slouken@2226
   148
struct _DFB_DeviceData
slouken@167
   149
{
slouken@1895
   150
    int initialized;
slouken@167
   151
slouken@1895
   152
    IDirectFB *dfb;
slouken@2226
   153
    int mouse;
slouken@2226
   154
    int keyboard;
slouken@2226
   155
    DFB_WindowData *firstwin;
slouken@167
   156
slouken@2226
   157
    int numscreens;
slouken@2226
   158
    DFBScreenID screenid[DFB_MAX_SCREENS];
slouken@2226
   159
    DFBDisplayLayerID gralayer[DFB_MAX_SCREENS];
slouken@2226
   160
    DFBDisplayLayerID vidlayer[DFB_MAX_SCREENS];
icculus@728
   161
slouken@2226
   162
    // auxiliary integer for callbacks
slouken@2226
   163
    int aux;
slouken@2226
   164
slouken@2226
   165
    // OpenGL
slouken@2226
   166
    void (*glFinish) (void);
slouken@2226
   167
    void (*glFlush) (void);
slouken@167
   168
};
slouken@167
   169
slouken@2226
   170
struct SDL_GLDriverData
slouken@2226
   171
{
slouken@2226
   172
    int gl_active;              /* to stop switching drivers while we have a valid context */
slouken@167
   173
slouken@2226
   174
#if SDL_DIRECTFB_OPENGL
slouken@2226
   175
    IDirectFBGL *gl_context;
slouken@2226
   176
#endif                          /* SDL_DIRECTFB_OPENGL */
slouken@2226
   177
};
slouken@478
   178
slouken@167
   179
#endif /* _SDL_DirectFB_video_h */