src/video/directfb/SDL_DirectFB_video.h
author Sam Lantinga
Mon, 16 Aug 2010 09:04:55 -0700
changeset 4636 b196d2758026
parent 4568 25b9cd8bdc30
child 5199 164f20ba08eb
permissions -rw-r--r--
Couriersud to Sam

Hi Sam,

20100815_1.diff contains updates for the directfb driver:

- more documentation, mainly on software OpenGL in README.directfb
- Revised error handling leading to leaner code
- Improved/fixed OpenGL handling of multiple contexts.
- Made the built-in simple window manager handle OpenGL windows.
- Rewrote pixelformat mapping - this was quite ugly before.

Well, all software GL, but working :-)
slouken@167
     1
/*
slouken@167
     2
    SDL - Simple DirectMedia Layer
slouken@3697
     3
    Copyright (C) 1997-2010 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@2737
    27
#include "../SDL_sysvideo.h"
slouken@2737
    28
slouken@167
    29
#include <directfb.h>
slouken@2226
    30
#include <directfb_version.h>
slouken@2226
    31
slouken@2737
    32
#include "SDL_mouse.h"
slouken@2737
    33
slouken@4568
    34
slouken@4568
    35
/* Set below to 1 to compile with (old) multi mice/keyboard api. Code left in
slouken@4568
    36
 * in case we see this again ... 
slouken@4568
    37
 */
slouken@4568
    38
slouken@4568
    39
#define USE_MULTI_API	(0)
slouken@4568
    40
slouken@4568
    41
#define DEBUG 1
slouken@2226
    42
#define LOG_CHANNEL 	stdout
slouken@2226
    43
couriersud@3037
    44
#define DFB_VERSIONNUM(X, Y, Z)						\
couriersud@3037
    45
	((X)*1000 + (Y)*100 + (Z))
couriersud@3037
    46
couriersud@3037
    47
#define DFB_COMPILEDVERSION \
couriersud@3037
    48
	DFB_VERSIONNUM(DIRECTFB_MAJOR_VERSION, DIRECTFB_MINOR_VERSION, DIRECTFB_MICRO_VERSION)
slouken@2226
    49
couriersud@3037
    50
#define DFB_VERSION_ATLEAST(X, Y, Z) \
couriersud@3037
    51
	(DFB_COMPILEDVERSION >= DFB_VERSIONNUM(X, Y, Z))
couriersud@3037
    52
couriersud@3037
    53
#if (DFB_VERSION_ATLEAST(1,0,0))
slouken@3040
    54
#define SDL_DIRECTFB_OPENGL 1
slouken@3040
    55
#include <directfbgl.h>
couriersud@3037
    56
#else
slouken@3040
    57
#error "SDL_DIRECTFB: Please compile against libdirectfb version >= 1.0.0"
slouken@2226
    58
#endif
slouken@2226
    59
slouken@2226
    60
#if SDL_DIRECTFB_OPENGL
slouken@2226
    61
#include "SDL_loadso.h"
slouken@2226
    62
#endif
slouken@167
    63
slouken@2737
    64
#include "SDL_DirectFB_events.h"
slouken@2737
    65
/*
slouken@2737
    66
 * #include "SDL_DirectFB_gamma.h"
slouken@2737
    67
 * #include "SDL_DirectFB_keyboard.h"
slouken@2737
    68
 */
slouken@2737
    69
#include "SDL_DirectFB_modes.h"
slouken@2737
    70
#include "SDL_DirectFB_mouse.h"
slouken@2737
    71
#include "SDL_DirectFB_opengl.h"
slouken@2737
    72
#include "SDL_DirectFB_window.h"
couriersud@3023
    73
#include "SDL_DirectFB_WM.h"
slouken@167
    74
slouken@2998
    75
#define DFBENV_USE_YUV_UNDERLAY 	"SDL_DIRECTFB_YUV_UNDERLAY"     /* Default: off */
slouken@2998
    76
#define DFBENV_USE_YUV_DIRECT   	"SDL_DIRECTFB_YUV_DIRECT"       /* Default: off */
slouken@2998
    77
#define DFBENV_USE_X11_CHECK		"SDL_DIRECTFB_X11_CHECK"        /* Default: on  */
slouken@2998
    78
#define DFBENV_USE_LINUX_INPUT		"SDL_DIRECTFB_LINUX_INPUT"      /* Default: on  */
slouken@3040
    79
#define DFBENV_USE_WM				"SDL_DIRECTFB_WM"       /* Default: off  */
slouken@2226
    80
slouken@4636
    81
#define SDL_DFB_RELEASE(x) do { if ( (x) != NULL ) { SDL_DFB_CHECK(x->Release(x)); x = NULL; } } while (0)
couriersud@3038
    82
#define SDL_DFB_FREE(x) do { if ( (x) != NULL ) { SDL_free(x); x = NULL; } } while (0)
couriersud@3038
    83
#define SDL_DFB_UNLOCK(x) do { if ( (x) != NULL ) { x->Unlock(x); } } while (0)
slouken@2226
    84
slouken@2226
    85
#if DEBUG
slouken@4636
    86
/* FIXME: do something with DEBUG */
slouken@2226
    87
#endif
slouken@2226
    88
slouken@2226
    89
#define SDL_DFB_CONTEXT "SDL_DirectFB"
slouken@2226
    90
slouken@4636
    91
static inline DFBResult sdl_dfb_check(DFBResult ret, const char *src_file, int src_line, const char *src_code) {
slouken@4636
    92
	if (ret != DFB_OK) {
slouken@4636
    93
		fprintf(LOG_CHANNEL, "%s <%d>:\n\t", src_file, src_line );
slouken@4636
    94
		fprintf(LOG_CHANNEL, "\t%s\n", src_code );
slouken@4636
    95
		fprintf(LOG_CHANNEL, "\t%s\n", DirectFBErrorString (ret) );
slouken@4636
    96
		SDL_SetError( src_code, DirectFBErrorString (ret) );
slouken@4636
    97
	}
slouken@4636
    98
	return ret;
slouken@4636
    99
}
slouken@4636
   100
slouken@4636
   101
#define SDL_DFB_CHECK(x...) sdl_dfb_check( x, __FILE__, __LINE__, #x )
slouken@4636
   102
slouken@4636
   103
#define SDL_DFB_CHECKERR(x...) if ( sdl_dfb_check( x, __FILE__, __LINE__, #x ) != DFB_OK ) goto error
slouken@4636
   104
slouken@4636
   105
#define SDL_DFB_DEBUG(x...) 							\
slouken@2226
   106
	do {											\
slouken@2226
   107
		fprintf(LOG_CHANNEL, "%s: %s <%d>:\n\t",			\
slouken@2226
   108
			SDL_DFB_CONTEXT, __FILE__, __LINE__ );	\
slouken@4636
   109
        fprintf(LOG_CHANNEL, x ); \
slouken@2226
   110
	} while (0)
slouken@2226
   111
slouken@4636
   112
#define SDL_DFB_ERR(x...) SDL_DFB_DEBUG( x )
slouken@2226
   113
slouken@2226
   114
#define SDL_DFB_CALLOC(r, n, s) \
slouken@2226
   115
     do {                                                                \
slouken@2226
   116
          r = SDL_calloc (n, s);                                      \
slouken@2226
   117
          if (!(r)) {                                                 \
slouken@2226
   118
               fprintf( LOG_CHANNEL, "%s <%d>:\n\t", __FILE__, __LINE__ ); \
slouken@2226
   119
               SDL_OutOfMemory();                                     \
slouken@2226
   120
               goto error; 					      \
slouken@2226
   121
          }                                                           \
slouken@2226
   122
     } while (0)
slouken@167
   123
slouken@167
   124
/* Private display data */
slouken@167
   125
couriersud@3023
   126
#define SDL_DFB_DEVICEDATA(dev)  DFB_DeviceData *devdata = (dev ? (DFB_DeviceData *) ((dev)->driverdata) : NULL)
slouken@2226
   127
slouken@2226
   128
#define DFB_MAX_SCREENS 10
slouken@2226
   129
slouken@2226
   130
typedef struct _DFB_DeviceData DFB_DeviceData;
slouken@2226
   131
struct _DFB_DeviceData
slouken@167
   132
{
slouken@1895
   133
    int initialized;
slouken@167
   134
slouken@1895
   135
    IDirectFB *dfb;
slouken@2860
   136
    int num_mice;
slouken@2860
   137
    int mouse_id[0x100];
slouken@2860
   138
    int num_keyboard;
slouken@2860
   139
    struct
slouken@2860
   140
    {
slouken@2860
   141
        int is_generic;
slouken@2860
   142
        int id;
slouken@2860
   143
    } keyboard[10];
slouken@2226
   144
    DFB_WindowData *firstwin;
icculus@728
   145
slouken@2737
   146
    int use_yuv_underlays;
slouken@2998
   147
    int use_linux_input;
couriersud@3023
   148
    int has_own_wm;
slouken@2226
   149
slouken@4636
   150
	/* window grab */
slouken@4636
   151
	SDL_Window *grabbed_window;
slouken@167
   152
slouken@2737
   153
    /* global events */
slouken@2737
   154
    IDirectFBEventBuffer *events;
slouken@2226
   155
};
slouken@478
   156
slouken@167
   157
#endif /* _SDL_DirectFB_video_h */