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