src/video/directfb/SDL_DirectFB_video.h
author Sam Lantinga
Sat, 05 Feb 2011 16:07:10 -0800
changeset 5199 164f20ba08eb
parent 4636 b196d2758026
child 5218 572a73d71b5f
permissions -rw-r--r--
Updated the DirectFB support, from Couriersud

attached is a working directfb driver diff which works with the current
changes. There are a number of changes around it as well, e.g.
configure.in.

The directfb renderdriver right now still depends on a some "includes"
from src/video/directfb. That's why it is not yet moved to the new
render folder.
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@5199
    21
slouken@5199
    22
    SDL1.3 DirectFB driver by couriersud@arcor.de
slouken@5199
    23
	
slouken@167
    24
*/
slouken@5199
    25
slouken@1402
    26
#include "SDL_config.h"
slouken@167
    27
slouken@167
    28
#ifndef _SDL_DirectFB_video_h
slouken@167
    29
#define _SDL_DirectFB_video_h
slouken@167
    30
slouken@167
    31
#include <directfb.h>
slouken@2226
    32
#include <directfb_version.h>
slouken@2226
    33
slouken@5199
    34
#include "../SDL_sysvideo.h"
slouken@5199
    35
#include "SDL_scancode.h"
slouken@5199
    36
#include "SDL_render.h"
slouken@2226
    37
couriersud@3037
    38
#define DFB_VERSIONNUM(X, Y, Z)						\
couriersud@3037
    39
	((X)*1000 + (Y)*100 + (Z))
couriersud@3037
    40
couriersud@3037
    41
#define DFB_COMPILEDVERSION \
couriersud@3037
    42
	DFB_VERSIONNUM(DIRECTFB_MAJOR_VERSION, DIRECTFB_MINOR_VERSION, DIRECTFB_MICRO_VERSION)
slouken@2226
    43
couriersud@3037
    44
#define DFB_VERSION_ATLEAST(X, Y, Z) \
couriersud@3037
    45
	(DFB_COMPILEDVERSION >= DFB_VERSIONNUM(X, Y, Z))
couriersud@3037
    46
couriersud@3037
    47
#if (DFB_VERSION_ATLEAST(1,0,0))
slouken@3040
    48
#define SDL_DIRECTFB_OPENGL 1
couriersud@3037
    49
#else
slouken@3040
    50
#error "SDL_DIRECTFB: Please compile against libdirectfb version >= 1.0.0"
slouken@2226
    51
#endif
slouken@2226
    52
slouken@5199
    53
/* Set below to 1 to compile with (old) multi mice/keyboard api. Code left in
slouken@5199
    54
 * in case we see this again ... 
slouken@5199
    55
 */
slouken@5199
    56
slouken@5199
    57
#define USE_MULTI_API	(0)
slouken@5199
    58
slouken@5199
    59
/* Support for LUT8/INDEX8 pixel format.
slouken@5199
    60
 * This is broken in DirectFB 1.4.3. It works in 1.4.0 and 1.4.5
slouken@5199
    61
 * occurred.
slouken@5199
    62
 */
slouken@5199
    63
slouken@5199
    64
#if (DFB_COMPILEDVERSION == DFB_VERSIONNUM(1, 4, 3))
slouken@5199
    65
#define ENABLE_LUT8		(0)
slouken@5199
    66
#else
slouken@5199
    67
#define ENABLE_LUT8		(1)
slouken@2226
    68
#endif
slouken@167
    69
slouken@5199
    70
#define DIRECTFB_DEBUG 1
slouken@5199
    71
#define LOG_CHANNEL 	stdout
slouken@167
    72
slouken@2998
    73
#define DFBENV_USE_YUV_UNDERLAY 	"SDL_DIRECTFB_YUV_UNDERLAY"     /* Default: off */
slouken@2998
    74
#define DFBENV_USE_YUV_DIRECT   	"SDL_DIRECTFB_YUV_DIRECT"       /* Default: off */
slouken@2998
    75
#define DFBENV_USE_X11_CHECK		"SDL_DIRECTFB_X11_CHECK"        /* Default: on  */
slouken@2998
    76
#define DFBENV_USE_LINUX_INPUT		"SDL_DIRECTFB_LINUX_INPUT"      /* Default: on  */
slouken@3040
    77
#define DFBENV_USE_WM				"SDL_DIRECTFB_WM"       /* Default: off  */
slouken@2226
    78
slouken@4636
    79
#define SDL_DFB_RELEASE(x) do { if ( (x) != NULL ) { SDL_DFB_CHECK(x->Release(x)); x = NULL; } } while (0)
couriersud@3038
    80
#define SDL_DFB_FREE(x) do { if ( (x) != NULL ) { SDL_free(x); x = NULL; } } while (0)
couriersud@3038
    81
#define SDL_DFB_UNLOCK(x) do { if ( (x) != NULL ) { x->Unlock(x); } } while (0)
slouken@2226
    82
slouken@2226
    83
#define SDL_DFB_CONTEXT "SDL_DirectFB"
slouken@2226
    84
slouken@5199
    85
#define SDL_DFB_ERR(x...) 							\
slouken@5199
    86
	do {											\
slouken@5199
    87
		fprintf(LOG_CHANNEL, "%s: %s <%d>:\n\t",	\
slouken@5199
    88
			SDL_DFB_CONTEXT, __FILE__, __LINE__ );	\
slouken@5199
    89
        fprintf(LOG_CHANNEL, x ); 					\
slouken@5199
    90
	} while (0)
slouken@5199
    91
slouken@5199
    92
#if (DIRECTFB_DEBUG)
slouken@5199
    93
slouken@5199
    94
#define SDL_DFB_LOG(x...) 							\
slouken@5199
    95
	do {											\
slouken@5199
    96
		fprintf(LOG_CHANNEL, SDL_DFB_CONTEXT);		\
slouken@5199
    97
        fprintf(LOG_CHANNEL, x ); 					\
slouken@5199
    98
		fprintf(LOG_CHANNEL, "\n");					\
slouken@5199
    99
	} while (0)
slouken@5199
   100
slouken@5199
   101
#define SDL_DFB_DEBUG(x...) SDL_DFB_ERR( x )
slouken@5199
   102
slouken@5199
   103
static inline DFBResult sdl_dfb_check(DFBResult ret, const char *src_file, int src_line) {
slouken@4636
   104
	if (ret != DFB_OK) {
slouken@5199
   105
		SDL_DFB_LOG("%s (%d):%s", src_file, src_line, DirectFBErrorString (ret) );
slouken@5199
   106
		SDL_SetError("%s:%s", SDL_DFB_CONTEXT, DirectFBErrorString (ret) );
slouken@4636
   107
	}
slouken@4636
   108
	return ret;
slouken@4636
   109
}
slouken@4636
   110
slouken@5199
   111
#define SDL_DFB_CHECK(x...) do { sdl_dfb_check( x, __FILE__, __LINE__); } while (0)
slouken@5199
   112
#define SDL_DFB_CHECKERR(x...) do { if ( sdl_dfb_check( x, __FILE__, __LINE__) != DFB_OK ) goto error; } while (0)
slouken@4636
   113
slouken@5199
   114
#else
slouken@4636
   115
slouken@5199
   116
#define SDL_DFB_CHECK(x...) x
slouken@5199
   117
#define SDL_DFB_CHECKERR(x...) do { if (x != DFB_OK ) goto error; } while (0)
slouken@5199
   118
#define SDL_DFB_LOG(x...) do {} while (0)
slouken@5199
   119
#define SDL_DFB_DEBUG(x...) do {} while (0)
slouken@2226
   120
slouken@5199
   121
#endif
slouken@5199
   122
slouken@2226
   123
slouken@2226
   124
#define SDL_DFB_CALLOC(r, n, s) \
slouken@5199
   125
     do {                                           \
slouken@5199
   126
          r = SDL_calloc (n, s);                    \
slouken@5199
   127
          if (!(r)) {                               \
slouken@5199
   128
               SDL_DFB_ERR("Out of memory"); 		\
slouken@5199
   129
               SDL_OutOfMemory();                   \
slouken@5199
   130
               goto error; 					      	\
slouken@5199
   131
          }                                         \
slouken@2226
   132
     } while (0)
slouken@167
   133
slouken@5199
   134
#define SDL_DFB_ALLOC_CLEAR(r, s) SDL_DFB_CALLOC(r, 1, s)
slouken@5199
   135
slouken@167
   136
/* Private display data */
slouken@167
   137
couriersud@3023
   138
#define SDL_DFB_DEVICEDATA(dev)  DFB_DeviceData *devdata = (dev ? (DFB_DeviceData *) ((dev)->driverdata) : NULL)
slouken@2226
   139
slouken@2226
   140
#define DFB_MAX_SCREENS 10
slouken@2226
   141
slouken@5199
   142
typedef struct _DFB_KeyboardData DFB_KeyboardData;
slouken@5199
   143
struct _DFB_KeyboardData
slouken@5199
   144
{
slouken@5199
   145
	const SDL_ScanCode	*map;		/* keyboard scancode map */
slouken@5199
   146
	int				map_size;	/* size of map */
slouken@5199
   147
	int				map_adjust; /* index adjust */
slouken@5199
   148
    int 			is_generic; /* generic keyboard */
slouken@5199
   149
    int id;
slouken@5199
   150
};
slouken@5199
   151
slouken@2226
   152
typedef struct _DFB_DeviceData DFB_DeviceData;
slouken@2226
   153
struct _DFB_DeviceData
slouken@167
   154
{
slouken@1895
   155
    int initialized;
slouken@167
   156
slouken@5199
   157
    IDirectFB 			*dfb;
slouken@5199
   158
    int 				num_mice;
slouken@5199
   159
    int 				mouse_id[0x100];
slouken@5199
   160
    int 				num_keyboard;
slouken@5199
   161
    DFB_KeyboardData 	keyboard[10];
slouken@5199
   162
    SDL_Window	 		*firstwin;
icculus@728
   163
slouken@5199
   164
    int 				use_yuv_underlays;
slouken@5199
   165
    int 				use_yuv_direct;
slouken@5199
   166
    int 				use_linux_input;
slouken@5199
   167
    int 				has_own_wm;
slouken@5199
   168
slouken@2226
   169
slouken@4636
   170
	/* window grab */
slouken@5199
   171
	SDL_Window 			*grabbed_window;
slouken@167
   172
slouken@2737
   173
    /* global events */
slouken@2737
   174
    IDirectFBEventBuffer *events;
slouken@2226
   175
};
slouken@478
   176
slouken@5199
   177
Uint32 DirectFB_DFBToSDLPixelFormat(DFBSurfacePixelFormat pixelformat);
slouken@5199
   178
DFBSurfacePixelFormat DirectFB_SDLToDFBPixelFormat(Uint32 format);
slouken@5199
   179
void DirectFB_SetSupportedPixelFormats(SDL_RendererInfo *ri);
slouken@5199
   180
slouken@5199
   181
slouken@167
   182
#endif /* _SDL_DirectFB_video_h */