Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
 This allows you to run an SDL program on a system without Xlib, since it'll
 just report the x11 target unavailable at runtime.
  • Loading branch information
icculus committed Nov 5, 2005
1 parent 04596c5 commit 402287e
Show file tree
Hide file tree
Showing 24 changed files with 948 additions and 520 deletions.
38 changes: 36 additions & 2 deletions configure.in
Expand Up @@ -609,11 +609,45 @@ CheckX11()
AC_PATH_X
AC_PATH_XTRA
if test x$have_x = xyes; then
CFLAGS="$CFLAGS $X_CFLAGS -DENABLE_X11 -DXTHREADS -I$srcdir/include -I$srcdir/src/video"
AC_ARG_ENABLE(x11-shared,
[ --enable-x11-shared dynamically load X11 support [default=yes]],
, enable_x11_shared=yes)

dnl !!! FIXME: make this work?
dnl x11_lib_spec=`echo $X11_LIBS | sed 's/.*-L\([[^ ]]*\).*/\1\/libX11.so.*/'`
dnl x11_lib=`ls $x11_lib_spec | sed 's/.*\/\(.*\)/\1/; q'`
dnl echo "-- $x11_lib_spec -> $x11_lib"
dnl x11ext_lib_spec=`echo $X11EXT_LIBS | sed 's/.*-L\([[^ ]]*\).*/\1\/libXext.so.*/'`
dnl x11ext_lib=`ls $x11ext_lib_spec | sed 's/.*\/\(.*\)/\1/; q'`
dnl echo "-- $x11ext_lib_spec -> $x11ext_lib"

x11_lib_spec='/usr/X11R6/lib/libX11.so.*'
x11_lib='libX11.so.6'
echo "-- $x11_lib_spec -> $x11_lib"
x11ext_lib_spec='/usr/X11R6/lib/libXext.so.*'
x11_lib='libXext.so.6'
echo "-- $x11ext_lib_spec -> $x11_lib"

if test x$use_dlopen != xyes && \
test x$enable_x11_shared = xyes; then
AC_MSG_ERROR([You must have dlopen() support and use the --enable-dlopen option])
fi

if test x$use_dlopen = xyes && \
test x$enable_x11_shared = xyes && test x$x11_lib != x; then
CFLAGS="$CFLAGS $X_CFLAGS -DENABLE_X11 -DXTHREADS -DX11_DYNAMIC=\$(x11_lib) -DX11EXT_DYNAMIC=\$(x11ext_lib) -I$srcdir/include -I$srcdir/src/video"
SYSTEM_LIBS="$SYSTEM_LIBS $X_LIBS"
AC_SUBST(x11_lib)
AC_SUBST(x11ext_lib)
else
CFLAGS="$CFLAGS $X_CFLAGS -DENABLE_X11 -DXTHREADS -I$srcdir/include -I$srcdir/src/video"
SYSTEM_LIBS="$SYSTEM_LIBS $X_LIBS -lX11 -lXext"
fi

if test x$ac_cv_func_shmat != xyes; then
CFLAGS="$CFLAGS -DNO_SHARED_MEMORY"
fi
SYSTEM_LIBS="$SYSTEM_LIBS $X_LIBS -lX11 -lXext"

VIDEO_SUBDIRS="$VIDEO_SUBDIRS x11"
VIDEO_DRIVERS="$VIDEO_DRIVERS x11/libvideo_x11.la"

Expand Down
21 changes: 14 additions & 7 deletions src/video/Xext/Xinerama/Xinerama.c
Expand Up @@ -35,6 +35,13 @@ Equipment Corporation.
#include "panoramiXproto.h" /* in ../include */
#include "Xinerama.h"

#include "../../x11/SDL_x11dyn.h"

/* Workaround code in headers... */
#define _XFlush p_XFlush
#define _XFlushGCCache p_XFlushGCCache
#define _XReply p_XReply
#define _XSend p_XSend

static XExtensionInfo _panoramiX_ext_info_data;
static XExtensionInfo *panoramiX_ext_info = &_panoramiX_ext_info_data;
Expand Down Expand Up @@ -111,7 +118,7 @@ Status SDL_NAME(XPanoramiXQueryVersion)(
req->panoramiXReqType = X_PanoramiXQueryVersion;
req->clientMajor = PANORAMIX_MAJOR_VERSION;
req->clientMinor = PANORAMIX_MINOR_VERSION;
if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
if (!p_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
UnlockDisplay (dpy);
SyncHandle ();
return 0;
Expand Down Expand Up @@ -145,7 +152,7 @@ Status SDL_NAME(XPanoramiXGetState) (
req->reqType = info->codes->major_opcode;
req->panoramiXReqType = X_PanoramiXGetState;
req->window = drawable;
if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
if (!p_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
UnlockDisplay (dpy);
SyncHandle ();
return 0;
Expand Down Expand Up @@ -174,7 +181,7 @@ Status SDL_NAME(XPanoramiXGetScreenCount) (
req->reqType = info->codes->major_opcode;
req->panoramiXReqType = X_PanoramiXGetScreenCount;
req->window = drawable;
if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
if (!p_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
UnlockDisplay (dpy);
SyncHandle ();
return 0;
Expand Down Expand Up @@ -205,7 +212,7 @@ Status SDL_NAME(XPanoramiXGetScreenSize) (
req->panoramiXReqType = X_PanoramiXGetScreenSize;
req->window = drawable;
req->screen = screen_num; /* need to define */
if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
if (!p_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
UnlockDisplay (dpy);
SyncHandle ();
return 0;
Expand Down Expand Up @@ -285,7 +292,7 @@ SDL_NAME(XineramaQueryScreens)(
GetReq (XineramaQueryScreens, req);
req->reqType = info->codes->major_opcode;
req->panoramiXReqType = X_XineramaQueryScreens;
if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) {
if (!p_XReply (dpy, (xReply *) &rep, 0, xFalse)) {
UnlockDisplay (dpy);
SyncHandle ();
return NULL;
Expand All @@ -297,7 +304,7 @@ SDL_NAME(XineramaQueryScreens)(
int i;

for(i = 0; i < rep.number; i++) {
_XRead(dpy, (char*)(&scratch), sz_XineramaScreenInfo);
p_XRead(dpy, (char*)(&scratch), sz_XineramaScreenInfo);
scrnInfo[i].screen_number = i;
scrnInfo[i].x_org = scratch.x_org;
scrnInfo[i].y_org = scratch.y_org;
Expand All @@ -307,7 +314,7 @@ SDL_NAME(XineramaQueryScreens)(

*number = rep.number;
} else
_XEatData(dpy, rep.length << 2);
p_XEatData(dpy, rep.length << 2);
}

UnlockDisplay (dpy);
Expand Down
50 changes: 29 additions & 21 deletions src/video/Xext/Xv/Xv.c
Expand Up @@ -56,6 +56,14 @@ SOFTWARE.
#include <X11/extensions/XShm.h>
#include "extutil.h"

#include "../../x11/SDL_x11dyn.h"

/* Workaround code in headers... */
#define _XFlush p_XFlush
#define _XFlushGCCache p_XFlushGCCache
#define _XReply p_XReply
#define _XSend p_XSend

static XExtensionInfo _xv_info_data;
static XExtensionInfo *xv_info = &_xv_info_data;
static char *xv_extension_name = XvName;
Expand Down Expand Up @@ -121,7 +129,7 @@ SDL_NAME(XvQueryExtension)(

XvGetReq(QueryExtension, req);

if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
if (!p_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return XvBadExtension;
Expand Down Expand Up @@ -171,7 +179,7 @@ SDL_NAME(XvQueryAdaptors)(

/* READ THE REPLY */

if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
if (p_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
UnlockDisplay(dpy);
SyncHandle();
return(XvBadReply);
Expand All @@ -183,7 +191,7 @@ SDL_NAME(XvQueryAdaptors)(
SyncHandle();
return(XvBadAlloc);
}
_XRead (dpy, buffer, size);
p_XRead (dpy, buffer, size);

u.buffer = buffer;

Expand Down Expand Up @@ -331,7 +339,7 @@ SDL_NAME(XvQueryEncodings)(

/* READ THE REPLY */

if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
if (p_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
UnlockDisplay(dpy);
SyncHandle();
return(XvBadReply);
Expand All @@ -343,7 +351,7 @@ SDL_NAME(XvQueryEncodings)(
SyncHandle();
return(XvBadAlloc);
}
_XRead (dpy, buffer, size);
p_XRead (dpy, buffer, size);

u.buffer = buffer;

Expand Down Expand Up @@ -619,7 +627,7 @@ SDL_NAME(XvGrabPort)(
req->port = port;
req->time = time;

if (_XReply (dpy, (xReply *) &rep, 0, xTrue) == 0)
if (p_XReply (dpy, (xReply *) &rep, 0, xTrue) == 0)
rep.result = GrabSuccess;

result = rep.result;
Expand Down Expand Up @@ -747,7 +755,7 @@ SDL_NAME(XvGetPortAttribute) (

/* READ THE REPLY */

if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
if (p_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
UnlockDisplay(dpy);
SyncHandle();
return(XvBadReply);
Expand Down Expand Up @@ -792,7 +800,7 @@ SDL_NAME(XvQueryBestSize)(

/* READ THE REPLY */

if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
if (p_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
UnlockDisplay(dpy);
SyncHandle();
return(XvBadReply);
Expand Down Expand Up @@ -827,7 +835,7 @@ SDL_NAME(XvQueryPortAttributes)(Display *dpy, XvPortID port, int *num)

/* READ THE REPLY */

if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
if (p_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
UnlockDisplay(dpy);
SyncHandle();
return ret;
Expand All @@ -842,17 +850,17 @@ SDL_NAME(XvQueryPortAttributes)(Display *dpy, XvPortID port, int *num)
int i;

for(i = 0; i < rep.num_attributes; i++) {
_XRead(dpy, (char*)(&Info), sz_xvAttributeInfo);
p_XRead(dpy, (char*)(&Info), sz_xvAttributeInfo);
ret[i].flags = (int)Info.flags;
ret[i].min_value = Info.min;
ret[i].max_value = Info.max;
ret[i].name = marker;
_XRead(dpy, marker, Info.size);
p_XRead(dpy, marker, Info.size);
marker += Info.size;
(*num)++;
}
} else
_XEatData(dpy, rep.length << 2);
p_XEatData(dpy, rep.length << 2);
}

UnlockDisplay(dpy);
Expand Down Expand Up @@ -882,7 +890,7 @@ SDL_NAME(XvImageFormatValues) * SDL_NAME(XvListImageFormats) (

/* READ THE REPLY */

if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
if (p_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
UnlockDisplay(dpy);
SyncHandle();
return NULL;
Expand All @@ -896,7 +904,7 @@ SDL_NAME(XvImageFormatValues) * SDL_NAME(XvListImageFormats) (
int i;

for(i = 0; i < rep.num_formats; i++) {
_XRead(dpy, (char*)(&Info), sz_xvImageFormatInfo);
p_XRead(dpy, (char*)(&Info), sz_xvImageFormatInfo);
ret[i].id = Info.id;
ret[i].type = Info.type;
ret[i].byte_order = Info.byte_order;
Expand All @@ -922,7 +930,7 @@ SDL_NAME(XvImageFormatValues) * SDL_NAME(XvListImageFormats) (
(*num)++;
}
} else
_XEatData(dpy, rep.length << 2);
p_XEatData(dpy, rep.length << 2);
}

UnlockDisplay(dpy);
Expand Down Expand Up @@ -956,7 +964,7 @@ SDL_NAME(XvImage) * SDL_NAME(XvCreateImage) (

/* READ THE REPLY */

if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
if (!p_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return NULL;
Expand All @@ -972,10 +980,10 @@ SDL_NAME(XvImage) * SDL_NAME(XvCreateImage) (
ret->offsets = ret->pitches + rep.num_planes;
ret->data = data;
ret->obdata = NULL;
_XRead(dpy, (char*)(ret->pitches), rep.num_planes << 2);
_XRead(dpy, (char*)(ret->offsets), rep.num_planes << 2);
p_XRead(dpy, (char*)(ret->pitches), rep.num_planes << 2);
p_XRead(dpy, (char*)(ret->offsets), rep.num_planes << 2);
} else
_XEatData(dpy, rep.length << 2);
p_XEatData(dpy, rep.length << 2);

UnlockDisplay(dpy);
SyncHandle();
Expand Down Expand Up @@ -1124,7 +1132,7 @@ xv_wire_to_event(Display *dpy, XEvent *host, xEvent *wire)
case XvVideoNotify:
re->xvvideo.type = event->u.u.type & 0x7f;
re->xvvideo.serial =
_XSetLastRequestRead(dpy, (xGenericReply *)event);
p_XSetLastRequestRead(dpy, (xGenericReply *)event);
re->xvvideo.send_event = ((event->u.u.type & 0x80) != 0);
re->xvvideo.display = dpy;
re->xvvideo.time = event->u.videoNotify.time;
Expand All @@ -1135,7 +1143,7 @@ xv_wire_to_event(Display *dpy, XEvent *host, xEvent *wire)
case XvPortNotify:
re->xvport.type = event->u.u.type & 0x7f;
re->xvport.serial =
_XSetLastRequestRead(dpy, (xGenericReply *)event);
p_XSetLastRequestRead(dpy, (xGenericReply *)event);
re->xvport.send_event = ((event->u.u.type & 0x80) != 0);
re->xvport.display = dpy;
re->xvport.time = event->u.portNotify.time;
Expand Down
4 changes: 2 additions & 2 deletions src/video/Xext/Xv/Xvlibint.h
Expand Up @@ -51,7 +51,7 @@ SOFTWARE.
#define XvGetReq(name, req) \
WORD64ALIGN\
if ((dpy->bufptr + SIZEOF(xv##name##Req)) > dpy->bufmax)\
_XFlush(dpy);\
p_XFlush(dpy);\
req = (xv##name##Req *)(dpy->last_req = dpy->bufptr);\
req->reqType = info->codes->major_opcode;\
req->xvReqType = xv_##name; \
Expand All @@ -63,7 +63,7 @@ SOFTWARE.
#define XvGetReq(name, req) \
WORD64ALIGN\
if ((dpy->bufptr + SIZEOF(xv/**/name/**/Req)) > dpy->bufmax)\
_XFlush(dpy);\
p_XFlush(dpy);\
req = (xv/**/name/**/Req *)(dpy->last_req = dpy->bufptr);\
req->reqType = info->codes->major_opcode;\
req->xvReqType = xv_/**/name;\
Expand Down

0 comments on commit 402287e

Please sign in to comment.