src/video/directfb/SDL_DirectFB_video.h
author Sam Lantinga
Mon, 14 Mar 2011 23:13:33 -0700
changeset 5488 c20436fd5627
parent 5262 b530ef003506
child 5535 96594ac5fd1a
permissions -rw-r--r--
DirectFB driver update

Couriersud to Sam

the attached patch brings the DirectFB driver back in line with recent
SDL 1.3 developments.
slouken@167
     1
/*
slouken@167
     2
    SDL - Simple DirectMedia Layer
slouken@5262
     3
    Copyright (C) 1997-2011 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@5488
    48
#ifdef SDL_VIDEO_OPENGL
slouken@3040
    49
#define SDL_DIRECTFB_OPENGL 1
slouken@5488
    50
#endif
couriersud@3037
    51
#else
slouken@3040
    52
#error "SDL_DIRECTFB: Please compile against libdirectfb version >= 1.0.0"
slouken@2226
    53
#endif
slouken@2226
    54
slouken@5199
    55
/* Set below to 1 to compile with (old) multi mice/keyboard api. Code left in
slouken@5199
    56
 * in case we see this again ... 
slouken@5199
    57
 */
slouken@5199
    58
slouken@5199
    59
#define USE_MULTI_API	(0)
slouken@5199
    60
slouken@5199
    61
/* Support for LUT8/INDEX8 pixel format.
slouken@5199
    62
 * This is broken in DirectFB 1.4.3. It works in 1.4.0 and 1.4.5
slouken@5199
    63
 * occurred.
slouken@5199
    64
 */
slouken@5199
    65
slouken@5199
    66
#if (DFB_COMPILEDVERSION == DFB_VERSIONNUM(1, 4, 3))
slouken@5199
    67
#define ENABLE_LUT8		(0)
slouken@5199
    68
#else
slouken@5199
    69
#define ENABLE_LUT8		(1)
slouken@2226
    70
#endif
slouken@167
    71
slouken@5199
    72
#define DIRECTFB_DEBUG 1
slouken@5199
    73
#define LOG_CHANNEL 	stdout
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
#define SDL_DFB_CONTEXT "SDL_DirectFB"
slouken@2226
    86
slouken@5199
    87
#define SDL_DFB_ERR(x...) 							\
slouken@5199
    88
	do {											\
slouken@5199
    89
		fprintf(LOG_CHANNEL, "%s: %s <%d>:\n\t",	\
slouken@5199
    90
			SDL_DFB_CONTEXT, __FILE__, __LINE__ );	\
slouken@5199
    91
        fprintf(LOG_CHANNEL, x ); 					\
slouken@5199
    92
	} while (0)
slouken@5199
    93
slouken@5199
    94
#if (DIRECTFB_DEBUG)
slouken@5199
    95
slouken@5199
    96
#define SDL_DFB_LOG(x...) 							\
slouken@5199
    97
	do {											\
slouken@5488
    98
		fprintf(LOG_CHANNEL, "%s: ", SDL_DFB_CONTEXT);		\
slouken@5199
    99
        fprintf(LOG_CHANNEL, x ); 					\
slouken@5199
   100
		fprintf(LOG_CHANNEL, "\n");					\
slouken@5199
   101
	} while (0)
slouken@5199
   102
slouken@5199
   103
#define SDL_DFB_DEBUG(x...) SDL_DFB_ERR( x )
slouken@5199
   104
slouken@5199
   105
static inline DFBResult sdl_dfb_check(DFBResult ret, const char *src_file, int src_line) {
slouken@4636
   106
	if (ret != DFB_OK) {
slouken@5199
   107
		SDL_DFB_LOG("%s (%d):%s", src_file, src_line, DirectFBErrorString (ret) );
slouken@5199
   108
		SDL_SetError("%s:%s", SDL_DFB_CONTEXT, DirectFBErrorString (ret) );
slouken@4636
   109
	}
slouken@4636
   110
	return ret;
slouken@4636
   111
}
slouken@4636
   112
slouken@5199
   113
#define SDL_DFB_CHECK(x...) do { sdl_dfb_check( x, __FILE__, __LINE__); } while (0)
slouken@5199
   114
#define SDL_DFB_CHECKERR(x...) do { if ( sdl_dfb_check( x, __FILE__, __LINE__) != DFB_OK ) goto error; } while (0)
slouken@4636
   115
slouken@5199
   116
#else
slouken@4636
   117
slouken@5199
   118
#define SDL_DFB_CHECK(x...) x
slouken@5199
   119
#define SDL_DFB_CHECKERR(x...) do { if (x != DFB_OK ) goto error; } while (0)
slouken@5199
   120
#define SDL_DFB_LOG(x...) do {} while (0)
slouken@5199
   121
#define SDL_DFB_DEBUG(x...) do {} while (0)
slouken@2226
   122
slouken@5199
   123
#endif
slouken@5199
   124
slouken@2226
   125
slouken@2226
   126
#define SDL_DFB_CALLOC(r, n, s) \
slouken@5199
   127
     do {                                           \
slouken@5199
   128
          r = SDL_calloc (n, s);                    \
slouken@5199
   129
          if (!(r)) {                               \
slouken@5199
   130
               SDL_DFB_ERR("Out of memory"); 		\
slouken@5199
   131
               SDL_OutOfMemory();                   \
slouken@5199
   132
               goto error; 					      	\
slouken@5199
   133
          }                                         \
slouken@2226
   134
     } while (0)
slouken@167
   135
slouken@5199
   136
#define SDL_DFB_ALLOC_CLEAR(r, s) SDL_DFB_CALLOC(r, 1, s)
slouken@5199
   137
slouken@167
   138
/* Private display data */
slouken@167
   139
couriersud@3023
   140
#define SDL_DFB_DEVICEDATA(dev)  DFB_DeviceData *devdata = (dev ? (DFB_DeviceData *) ((dev)->driverdata) : NULL)
slouken@2226
   141
slouken@2226
   142
#define DFB_MAX_SCREENS 10
slouken@2226
   143
slouken@5199
   144
typedef struct _DFB_KeyboardData DFB_KeyboardData;
slouken@5199
   145
struct _DFB_KeyboardData
slouken@5199
   146
{
slouken@5218
   147
	const SDL_Scancode	*map;		/* keyboard scancode map */
slouken@5199
   148
	int				map_size;	/* size of map */
slouken@5199
   149
	int				map_adjust; /* index adjust */
slouken@5199
   150
    int 			is_generic; /* generic keyboard */
slouken@5199
   151
    int id;
slouken@5199
   152
};
slouken@5199
   153
slouken@2226
   154
typedef struct _DFB_DeviceData DFB_DeviceData;
slouken@2226
   155
struct _DFB_DeviceData
slouken@167
   156
{
slouken@1895
   157
    int initialized;
slouken@167
   158
slouken@5199
   159
    IDirectFB 			*dfb;
slouken@5199
   160
    int 				num_mice;
slouken@5199
   161
    int 				mouse_id[0x100];
slouken@5199
   162
    int 				num_keyboard;
slouken@5199
   163
    DFB_KeyboardData 	keyboard[10];
slouken@5199
   164
    SDL_Window	 		*firstwin;
icculus@728
   165
slouken@5199
   166
    int 				use_yuv_underlays;
slouken@5199
   167
    int 				use_yuv_direct;
slouken@5199
   168
    int 				use_linux_input;
slouken@5199
   169
    int 				has_own_wm;
slouken@5199
   170
slouken@2226
   171
slouken@4636
   172
	/* window grab */
slouken@5199
   173
	SDL_Window 			*grabbed_window;
slouken@167
   174
slouken@2737
   175
    /* global events */
slouken@2737
   176
    IDirectFBEventBuffer *events;
slouken@2226
   177
};
slouken@478
   178
slouken@5199
   179
Uint32 DirectFB_DFBToSDLPixelFormat(DFBSurfacePixelFormat pixelformat);
slouken@5199
   180
DFBSurfacePixelFormat DirectFB_SDLToDFBPixelFormat(Uint32 format);
slouken@5199
   181
void DirectFB_SetSupportedPixelFormats(SDL_RendererInfo *ri);
slouken@5199
   182
slouken@5199
   183
slouken@167
   184
#endif /* _SDL_DirectFB_video_h */