src/video/x11/SDL_x11dyn.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 21 Feb 2006 08:46:50 +0000
changeset 1402 d910939febfa
parent 1361 19418e4422cb
child 1575 3ba88cb7eb1b
permissions -rw-r--r--
Use consistent identifiers for the various platforms we support.
Make sure every source file includes SDL_config.h, so the proper system
headers are chosen.
icculus@1168
     1
/*
icculus@1168
     2
    SDL - Simple DirectMedia Layer
icculus@1168
     3
    Copyright (C) 1997-2004 Sam Lantinga
icculus@1168
     4
icculus@1168
     5
    This library is free software; you can redistribute it and/or
icculus@1168
     6
    modify it under the terms of the GNU Library General Public
icculus@1168
     7
    License as published by the Free Software Foundation; either
icculus@1168
     8
    version 2 of the License, or (at your option) any later version.
icculus@1168
     9
icculus@1168
    10
    This library is distributed in the hope that it will be useful,
icculus@1168
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
icculus@1168
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
icculus@1168
    13
    Library General Public License for more details.
icculus@1168
    14
icculus@1168
    15
    You should have received a copy of the GNU Library General Public
icculus@1168
    16
    License along with this library; if not, write to the Free
icculus@1168
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
icculus@1168
    18
icculus@1168
    19
    Sam Lantinga
icculus@1168
    20
    slouken@libsdl.org
icculus@1168
    21
*/
slouken@1402
    22
#include "SDL_config.h"
icculus@1168
    23
icculus@1235
    24
#if 0
icculus@1235
    25
#define DEBUG_DYNAMIC_X11 1
icculus@1235
    26
#endif
icculus@1168
    27
icculus@1226
    28
#define __SDL_NO_REDEFINE_X11_HEADER_SYMS 1
icculus@1168
    29
#include "SDL_x11dyn.h"
icculus@1168
    30
icculus@1168
    31
#ifdef DEBUG_DYNAMIC_X11
icculus@1168
    32
#include <stdio.h>
icculus@1168
    33
#endif
icculus@1168
    34
slouken@1361
    35
#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
icculus@1168
    36
#include <dlfcn.h>
icculus@1168
    37
#include "SDL_name.h"
icculus@1168
    38
#include "SDL_loadso.h"
slouken@1361
    39
static const char *x11_library = SDL_VIDEO_DRIVER_X11_DYNAMIC;
icculus@1168
    40
static void *x11_handle = NULL;
slouken@1361
    41
static const char *x11ext_library = SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT;
icculus@1168
    42
static void *x11ext_handle = NULL;
icculus@1168
    43
icculus@1235
    44
static void *X11_GetSym(int required, const char *fnname, int *rc)
icculus@1168
    45
{
icculus@1168
    46
	void *fn = NULL;
icculus@1168
    47
	if (*rc) {  /* haven't already failed on a previous lookup? */
icculus@1168
    48
		fn = SDL_LoadFunction(x11_handle, fnname);
icculus@1168
    49
		#if DEBUG_DYNAMIC_X11
icculus@1168
    50
		if (fn != NULL)
icculus@1168
    51
			printf("X11: Found '%s' in libX11 (%p)\n", fnname, fn);
icculus@1168
    52
		#endif
icculus@1168
    53
icculus@1168
    54
		if (fn == NULL) {  /* not found? Check libX11ext ... */
icculus@1168
    55
			fn = SDL_LoadFunction(x11ext_handle, fnname);
icculus@1168
    56
			#if DEBUG_DYNAMIC_X11
icculus@1168
    57
			if (fn != NULL)
icculus@1168
    58
				printf("X11: Found '%s' in libXext (%p)\n", fnname, fn);
icculus@1168
    59
			else
icculus@1245
    60
				printf("X11: Symbol '%s' NOT FOUND!%s\n", fnname,
icculus@1236
    61
				       required ? "" : " (...but not required!)");
icculus@1168
    62
			#endif
icculus@1168
    63
		}
icculus@1235
    64
		*rc = ((fn != NULL) || (!required));
icculus@1168
    65
	}
icculus@1168
    66
icculus@1168
    67
	return fn;
icculus@1168
    68
}
slouken@1361
    69
#endif  /* SDL_VIDEO_DRIVER_X11_DYNAMIC */
icculus@1168
    70
icculus@1168
    71
/* Define all the function pointers... */
icculus@1235
    72
#define SDL_X11_SYM(req,ret,fn,params) ret (*p##fn) params = NULL;
icculus@1168
    73
#include "SDL_x11sym.h"
icculus@1168
    74
#undef SDL_X11_SYM
icculus@1168
    75
icculus@1168
    76
static int x11_load_refcount = 0;
icculus@1168
    77
icculus@1168
    78
void SDL_X11_UnloadSymbols(void)
icculus@1168
    79
{
icculus@1168
    80
	/* Don't actually unload if more than one module is using the libs... */
icculus@1168
    81
	if (x11_load_refcount > 0) {
icculus@1168
    82
		if (--x11_load_refcount == 0) {
icculus@1168
    83
			/* set all the function pointers to NULL. */
icculus@1235
    84
			#define SDL_X11_SYM(req,ret,fn,params) p##fn = NULL;
icculus@1168
    85
			#include "SDL_x11sym.h"
icculus@1168
    86
			#undef SDL_X11_SYM
icculus@1168
    87
slouken@1361
    88
			#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
icculus@1168
    89
			if (x11_handle != NULL) {
icculus@1168
    90
				SDL_UnloadObject(x11_handle);
icculus@1168
    91
				x11_handle = NULL;
icculus@1168
    92
			}
icculus@1168
    93
			if (x11ext_handle != NULL) {
icculus@1168
    94
				SDL_UnloadObject(x11ext_handle);
icculus@1168
    95
				x11ext_handle = NULL;
icculus@1168
    96
			}
icculus@1168
    97
			#endif
icculus@1168
    98
		}
icculus@1168
    99
	}
icculus@1168
   100
}
icculus@1168
   101
icculus@1168
   102
/* returns non-zero if all needed symbols were loaded. */
icculus@1168
   103
int SDL_X11_LoadSymbols(void)
icculus@1168
   104
{
icculus@1168
   105
	int rc = 1;
icculus@1168
   106
icculus@1168
   107
    /* deal with multiple modules (dga, x11, etc) needing these symbols... */
icculus@1168
   108
	if (x11_load_refcount++ == 0) {
slouken@1361
   109
		#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
icculus@1168
   110
			x11_handle = SDL_LoadObject(x11_library);
icculus@1168
   111
			x11ext_handle = SDL_LoadObject(x11ext_library);
icculus@1171
   112
			rc = ((x11_handle != NULL) && (x11ext_handle != NULL));
icculus@1235
   113
			#define SDL_X11_SYM(req,r,fn,arg) p##fn = X11_GetSym(req,#fn, &rc);
icculus@1171
   114
			#include "SDL_x11sym.h"
icculus@1171
   115
			#undef SDL_X11_SYM
icculus@1168
   116
icculus@1168
   117
			if (!rc)
icculus@1168
   118
				SDL_X11_UnloadSymbols();  /* in case one of these loaded... */
icculus@1168
   119
icculus@1168
   120
		#else
icculus@1235
   121
			#define SDL_X11_SYM(req,r,fn,arg) p##fn = fn;
icculus@1168
   122
			#include "SDL_x11sym.h"
icculus@1168
   123
			#undef SDL_X11_SYM
icculus@1168
   124
		#endif
icculus@1168
   125
	}
icculus@1168
   126
icculus@1168
   127
	return rc;
icculus@1168
   128
}
icculus@1168
   129
icculus@1168
   130
/* end of SDL_x11dyn.c ... */
icculus@1168
   131