src/video/directfb/SDL_DirectFB_video.h
author Sam Lantinga
Fri, 08 Apr 2011 13:03:26 -0700
changeset 5535 96594ac5fd1a
parent 5488 c20436fd5627
child 6138 4c64952a58fb
permissions -rw-r--r--
SDL 1.3 is now under the zlib license.
slouken@167
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@5535
     3
  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
slouken@167
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@167
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@167
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@167
    20
*/
slouken@5199
    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@5199
    30
#include "../SDL_sysvideo.h"
slouken@5199
    31
#include "SDL_scancode.h"
slouken@5199
    32
#include "SDL_render.h"
slouken@2226
    33
couriersud@3037
    34
#define DFB_VERSIONNUM(X, Y, Z)						\
couriersud@3037
    35
	((X)*1000 + (Y)*100 + (Z))
couriersud@3037
    36
couriersud@3037
    37
#define DFB_COMPILEDVERSION \
couriersud@3037
    38
	DFB_VERSIONNUM(DIRECTFB_MAJOR_VERSION, DIRECTFB_MINOR_VERSION, DIRECTFB_MICRO_VERSION)
slouken@2226
    39
couriersud@3037
    40
#define DFB_VERSION_ATLEAST(X, Y, Z) \
couriersud@3037
    41
	(DFB_COMPILEDVERSION >= DFB_VERSIONNUM(X, Y, Z))
couriersud@3037
    42
couriersud@3037
    43
#if (DFB_VERSION_ATLEAST(1,0,0))
slouken@5488
    44
#ifdef SDL_VIDEO_OPENGL
slouken@3040
    45
#define SDL_DIRECTFB_OPENGL 1
slouken@5488
    46
#endif
couriersud@3037
    47
#else
slouken@3040
    48
#error "SDL_DIRECTFB: Please compile against libdirectfb version >= 1.0.0"
slouken@2226
    49
#endif
slouken@2226
    50
slouken@5199
    51
/* Set below to 1 to compile with (old) multi mice/keyboard api. Code left in
slouken@5199
    52
 * in case we see this again ... 
slouken@5199
    53
 */
slouken@5199
    54
slouken@5199
    55
#define USE_MULTI_API	(0)
slouken@5199
    56
slouken@5199
    57
/* Support for LUT8/INDEX8 pixel format.
slouken@5199
    58
 * This is broken in DirectFB 1.4.3. It works in 1.4.0 and 1.4.5
slouken@5199
    59
 * occurred.
slouken@5199
    60
 */
slouken@5199
    61
slouken@5199
    62
#if (DFB_COMPILEDVERSION == DFB_VERSIONNUM(1, 4, 3))
slouken@5199
    63
#define ENABLE_LUT8		(0)
slouken@5199
    64
#else
slouken@5199
    65
#define ENABLE_LUT8		(1)
slouken@2226
    66
#endif
slouken@167
    67
slouken@5199
    68
#define DIRECTFB_DEBUG 1
slouken@5199
    69
#define LOG_CHANNEL 	stdout
slouken@167
    70
slouken@2998
    71
#define DFBENV_USE_YUV_UNDERLAY 	"SDL_DIRECTFB_YUV_UNDERLAY"     /* Default: off */
slouken@2998
    72
#define DFBENV_USE_YUV_DIRECT   	"SDL_DIRECTFB_YUV_DIRECT"       /* Default: off */
slouken@2998
    73
#define DFBENV_USE_X11_CHECK		"SDL_DIRECTFB_X11_CHECK"        /* Default: on  */
slouken@2998
    74
#define DFBENV_USE_LINUX_INPUT		"SDL_DIRECTFB_LINUX_INPUT"      /* Default: on  */
slouken@3040
    75
#define DFBENV_USE_WM				"SDL_DIRECTFB_WM"       /* Default: off  */
slouken@2226
    76
slouken@4636
    77
#define SDL_DFB_RELEASE(x) do { if ( (x) != NULL ) { SDL_DFB_CHECK(x->Release(x)); x = NULL; } } while (0)
couriersud@3038
    78
#define SDL_DFB_FREE(x) do { if ( (x) != NULL ) { SDL_free(x); x = NULL; } } while (0)
couriersud@3038
    79
#define SDL_DFB_UNLOCK(x) do { if ( (x) != NULL ) { x->Unlock(x); } } while (0)
slouken@2226
    80
slouken@2226
    81
#define SDL_DFB_CONTEXT "SDL_DirectFB"
slouken@2226
    82
slouken@5199
    83
#define SDL_DFB_ERR(x...) 							\
slouken@5199
    84
	do {											\
slouken@5199
    85
		fprintf(LOG_CHANNEL, "%s: %s <%d>:\n\t",	\
slouken@5199
    86
			SDL_DFB_CONTEXT, __FILE__, __LINE__ );	\
slouken@5199
    87
        fprintf(LOG_CHANNEL, x ); 					\
slouken@5199
    88
	} while (0)
slouken@5199
    89
slouken@5199
    90
#if (DIRECTFB_DEBUG)
slouken@5199
    91
slouken@5199
    92
#define SDL_DFB_LOG(x...) 							\
slouken@5199
    93
	do {											\
slouken@5488
    94
		fprintf(LOG_CHANNEL, "%s: ", SDL_DFB_CONTEXT);		\
slouken@5199
    95
        fprintf(LOG_CHANNEL, x ); 					\
slouken@5199
    96
		fprintf(LOG_CHANNEL, "\n");					\
slouken@5199
    97
	} while (0)
slouken@5199
    98
slouken@5199
    99
#define SDL_DFB_DEBUG(x...) SDL_DFB_ERR( x )
slouken@5199
   100
slouken@5199
   101
static inline DFBResult sdl_dfb_check(DFBResult ret, const char *src_file, int src_line) {
slouken@4636
   102
	if (ret != DFB_OK) {
slouken@5199
   103
		SDL_DFB_LOG("%s (%d):%s", src_file, src_line, DirectFBErrorString (ret) );
slouken@5199
   104
		SDL_SetError("%s:%s", SDL_DFB_CONTEXT, DirectFBErrorString (ret) );
slouken@4636
   105
	}
slouken@4636
   106
	return ret;
slouken@4636
   107
}
slouken@4636
   108
slouken@5199
   109
#define SDL_DFB_CHECK(x...) do { sdl_dfb_check( x, __FILE__, __LINE__); } while (0)
slouken@5199
   110
#define SDL_DFB_CHECKERR(x...) do { if ( sdl_dfb_check( x, __FILE__, __LINE__) != DFB_OK ) goto error; } while (0)
slouken@4636
   111
slouken@5199
   112
#else
slouken@4636
   113
slouken@5199
   114
#define SDL_DFB_CHECK(x...) x
slouken@5199
   115
#define SDL_DFB_CHECKERR(x...) do { if (x != DFB_OK ) goto error; } while (0)
slouken@5199
   116
#define SDL_DFB_LOG(x...) do {} while (0)
slouken@5199
   117
#define SDL_DFB_DEBUG(x...) do {} while (0)
slouken@2226
   118
slouken@5199
   119
#endif
slouken@5199
   120
slouken@2226
   121
slouken@2226
   122
#define SDL_DFB_CALLOC(r, n, s) \
slouken@5199
   123
     do {                                           \
slouken@5199
   124
          r = SDL_calloc (n, s);                    \
slouken@5199
   125
          if (!(r)) {                               \
slouken@5199
   126
               SDL_DFB_ERR("Out of memory"); 		\
slouken@5199
   127
               SDL_OutOfMemory();                   \
slouken@5199
   128
               goto error; 					      	\
slouken@5199
   129
          }                                         \
slouken@2226
   130
     } while (0)
slouken@167
   131
slouken@5199
   132
#define SDL_DFB_ALLOC_CLEAR(r, s) SDL_DFB_CALLOC(r, 1, s)
slouken@5199
   133
slouken@167
   134
/* Private display data */
slouken@167
   135
couriersud@3023
   136
#define SDL_DFB_DEVICEDATA(dev)  DFB_DeviceData *devdata = (dev ? (DFB_DeviceData *) ((dev)->driverdata) : NULL)
slouken@2226
   137
slouken@2226
   138
#define DFB_MAX_SCREENS 10
slouken@2226
   139
slouken@5199
   140
typedef struct _DFB_KeyboardData DFB_KeyboardData;
slouken@5199
   141
struct _DFB_KeyboardData
slouken@5199
   142
{
slouken@5218
   143
	const SDL_Scancode	*map;		/* keyboard scancode map */
slouken@5199
   144
	int				map_size;	/* size of map */
slouken@5199
   145
	int				map_adjust; /* index adjust */
slouken@5199
   146
    int 			is_generic; /* generic keyboard */
slouken@5199
   147
    int id;
slouken@5199
   148
};
slouken@5199
   149
slouken@2226
   150
typedef struct _DFB_DeviceData DFB_DeviceData;
slouken@2226
   151
struct _DFB_DeviceData
slouken@167
   152
{
slouken@1895
   153
    int initialized;
slouken@167
   154
slouken@5199
   155
    IDirectFB 			*dfb;
slouken@5199
   156
    int 				num_mice;
slouken@5199
   157
    int 				mouse_id[0x100];
slouken@5199
   158
    int 				num_keyboard;
slouken@5199
   159
    DFB_KeyboardData 	keyboard[10];
slouken@5199
   160
    SDL_Window	 		*firstwin;
icculus@728
   161
slouken@5199
   162
    int 				use_yuv_underlays;
slouken@5199
   163
    int 				use_yuv_direct;
slouken@5199
   164
    int 				use_linux_input;
slouken@5199
   165
    int 				has_own_wm;
slouken@5199
   166
slouken@2226
   167
slouken@4636
   168
	/* window grab */
slouken@5199
   169
	SDL_Window 			*grabbed_window;
slouken@167
   170
slouken@2737
   171
    /* global events */
slouken@2737
   172
    IDirectFBEventBuffer *events;
slouken@2226
   173
};
slouken@478
   174
slouken@5199
   175
Uint32 DirectFB_DFBToSDLPixelFormat(DFBSurfacePixelFormat pixelformat);
slouken@5199
   176
DFBSurfacePixelFormat DirectFB_SDLToDFBPixelFormat(Uint32 format);
slouken@5199
   177
void DirectFB_SetSupportedPixelFormats(SDL_RendererInfo *ri);
slouken@5199
   178
slouken@5199
   179
slouken@167
   180
#endif /* _SDL_DirectFB_video_h */