From 8c237a452cd458cd82566fdd5b625e4c4fd52b9b Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 4 Jan 2009 23:43:33 +0000 Subject: [PATCH] Date: Sun, 04 Jan 2009 20:53:30 +0100 From: Couriersud Subject: SDL1.3 DirectFB patches The attached contains the following directfb changes: - Dynamic loading of libdirectfb.so. This may to turned off as well in configure - Use linux-input by default. May be switched off by environment variable. - Added some code which will use directfb's x11 backend when DISPLAY is set. --- README.DirectFB | 12 +++++- configure.in | 28 +++++++++++++- include/SDL_config.h.in | 1 + src/video/directfb/SDL_DirectFB_events.c | 16 ++++---- src/video/directfb/SDL_DirectFB_mouse.c | 4 +- src/video/directfb/SDL_DirectFB_opengl.c | 4 ++ src/video/directfb/SDL_DirectFB_video.c | 48 ++++++++++++++++++++---- src/video/directfb/SDL_DirectFB_video.h | 9 +++-- 8 files changed, 97 insertions(+), 25 deletions(-) diff --git a/README.DirectFB b/README.DirectFB index a5d404ee3..74777e8dd 100644 --- a/README.DirectFB +++ b/README.DirectFB @@ -20,12 +20,20 @@ This file should contain the following lines to make your joystick work and avoid crashes: ------------------------ disable-module=joystick -disable-module=linux_input disable-module=cle266 disable-module=cyber5k -disable-module=x11input +no-linux-input-grab ------------------------ +To disable to use x11 backend when DISPLAY variable is found use + +export SDL_DIRECTFB_X11_CHECK=0 + +To disable the use of linux input devices, i.e. multimice/multikeyboard support, +use + +export SDL_DIRECTFB_LINUX_INPUT=0 + To use hardware accelerated YUV-overlays for YUV-textures, use: export SDL_DIRECTFB_YUV_DIRECT=1 diff --git a/configure.in b/configure.in index 44732f9de..088750d61 100644 --- a/configure.in +++ b/configure.in @@ -1311,7 +1311,7 @@ AC_HELP_STRING([--enable-video-directfb], [use DirectFB video driver [[default=n if test x$enable_video = xyes -a x$enable_video_directfb = xyes; then video_directfb=no - DIRECTFB_REQUIRED_VERSION=0.9.15 + DIRECTFB_REQUIRED_VERSION=1.0.0 AC_PATH_PROG(DIRECTFBCONFIG, directfb-config, no) if test x$DIRECTFBCONFIG = xno; then @@ -1321,6 +1321,7 @@ AC_HELP_STRING([--enable-video-directfb], [use DirectFB video driver [[default=n if $PKG_CONFIG --atleast-pkgconfig-version 0.7 && $PKG_CONFIG --atleast-version $DIRECTFB_REQUIRED_VERSION directfb; then DIRECTFB_CFLAGS=`$PKG_CONFIG --cflags directfb` DIRECTFB_LIBS=`$PKG_CONFIG --libs directfb` + DIRECTFB_PREFIX=`$PKG_CONFIG --variable=prefix directfb` video_directfb=yes fi fi @@ -1334,16 +1335,39 @@ AC_HELP_STRING([--enable-video-directfb], [use DirectFB video driver [[default=n if test $HAVE_VERSION -ge $NEED_VERSION; then DIRECTFB_CFLAGS=`$DIRECTFBCONFIG --cflags` DIRECTFB_LIBS=`$DIRECTFBCONFIG --libs` + DIRECTFB_PREFIX=`$DIRECTFBCONFIG --prefix` video_directfb=yes fi AC_MSG_RESULT($video_directfb) fi if test x$video_directfb = xyes; then + AC_ARG_ENABLE(directfb-shared, +AC_HELP_STRING([--enable-directfb-shared], [dynamically load directfb support [[default=yes]]]), + , enable_directfb_shared=yes) + AC_DEFINE(SDL_VIDEO_DRIVER_DIRECTFB) SOURCES="$SOURCES $srcdir/src/video/directfb/*.c" EXTRA_CFLAGS="$EXTRA_CFLAGS $DIRECTFB_CFLAGS" - EXTRA_LDFLAGS="$EXTRA_LDFLAGS $DIRECTFB_LIBS" + + AC_MSG_CHECKING(for directfb dynamic loading support) + directfb_shared=no + directfb_lib_spec="$DIRECTFB_PREFIX/lib/libdirectfb.so*" + directfb_lib=`ls -- $directfb_lib_spec | sed 's/.*\/\(.*\)/\1/; q'` + dnl echo "-- $directfb_lib_spec -> $directfb_lib" + + if test x$have_loadso != xyes && \ + test x$enable_directfb_shared = xyes; then + AC_MSG_WARN([You must have SDL_LoadObject() support for dynamic directfb loading]) + fi + if test x$have_loadso = xyes && \ + test x$enable_directfb_shared = xyes && test x$directfb_lib != x; then + directfb_shared=yes + AC_DEFINE_UNQUOTED(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC, "$directfb_lib") + else + EXTRA_LDFLAGS="$EXTRA_LDFLAGS $DIRECTFB_LIBS" + fi + AC_MSG_RESULT($directfb_shared) have_video=yes fi fi diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in index 2831605ad..ae7442b4a 100644 --- a/include/SDL_config.h.in +++ b/include/SDL_config.h.in @@ -263,6 +263,7 @@ #undef SDL_VIDEO_DRIVER_COCOA #undef SDL_VIDEO_DRIVER_DC #undef SDL_VIDEO_DRIVER_DIRECTFB +#undef SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC #undef SDL_VIDEO_DRIVER_DUMMY #undef SDL_VIDEO_DRIVER_FBCON #undef SDL_VIDEO_DRIVER_GAPI diff --git a/src/video/directfb/SDL_DirectFB_events.c b/src/video/directfb/SDL_DirectFB_events.c index 11e7a1757..c9b00c546 100644 --- a/src/video/directfb/SDL_DirectFB_events.c +++ b/src/video/directfb/SDL_DirectFB_events.c @@ -144,7 +144,7 @@ DirectFB_PumpEventsWindow(_THIS) if (evt.clazz == DFEC_WINDOW) { switch (evt.type) { case DWET_BUTTONDOWN: - if (!LINUX_INPUT_SUPPORT) { + if (!devdata->use_linux_input) { SDL_SendMouseMotion(devdata->mouse_id[0], 0, evt.cx, evt.cy, 0); SDL_SendMouseButton(devdata->mouse_id[0], SDL_PRESSED, @@ -155,7 +155,7 @@ DirectFB_PumpEventsWindow(_THIS) } break; case DWET_BUTTONUP: - if (!LINUX_INPUT_SUPPORT) { + if (!devdata->use_linux_input) { SDL_SendMouseMotion(devdata->mouse_id[0], 0, evt.cx, evt.cy, 0); SDL_SendMouseButton(devdata->mouse_id[0], @@ -167,7 +167,7 @@ DirectFB_PumpEventsWindow(_THIS) } break; case DWET_MOTION: - if (!LINUX_INPUT_SUPPORT) { + if (!devdata->use_linux_input) { if (!(w->flags & SDL_WINDOW_INPUT_GRABBED)) SDL_SendMouseMotion(devdata->mouse_id[0], 0, evt.cx, evt.cy, 0); @@ -183,7 +183,7 @@ DirectFB_PumpEventsWindow(_THIS) } break; case DWET_KEYDOWN: - if (!LINUX_INPUT_SUPPORT) { + if (!devdata->use_linux_input) { DirectFB_TranslateKey(_this, &evt, &keysym); SDL_SendKeyboardKey(0, SDL_PRESSED, keysym.scancode); if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) { @@ -196,7 +196,7 @@ DirectFB_PumpEventsWindow(_THIS) } break; case DWET_KEYUP: - if (!LINUX_INPUT_SUPPORT) { + if (!devdata->use_linux_input) { DirectFB_TranslateKey(_this, &evt, &keysym); SDL_SendKeyboardKey(0, SDL_RELEASED, keysym.scancode); } @@ -260,7 +260,7 @@ DirectFB_PumpEventsWindow(_THIS) switch (ievt.type) { case DIET_AXISMOTION: - if (!LINUX_INPUT_SUPPORT) { + if (!devdata->use_linux_input) { if ((grabbed_window >= 0) && (ievt.flags & DIEF_AXISREL)) { printf("rel devid %d\n", ievt.device_id); if (ievt.axis == DIAI_X) @@ -273,7 +273,7 @@ DirectFB_PumpEventsWindow(_THIS) } break; } - if (LINUX_INPUT_SUPPORT) { + if (devdata->use_linux_input) { IDirectFBInputDevice *idev; static int last_x, last_y; @@ -600,7 +600,7 @@ DirectFB_InitKeyboard(_THIS) DirectFB_InitOSKeymap(_this, &oskeymap[0], SDL_arraysize(oskeymap)); devdata->num_keyboard = 0; - if (LINUX_INPUT_SUPPORT) { + if (devdata->use_linux_input) { sys_ids = 0; SDL_DFB_CHECK(devdata->dfb-> EnumInputDevices(devdata->dfb, EnumKeyboards, devdata)); diff --git a/src/video/directfb/SDL_DirectFB_mouse.c b/src/video/directfb/SDL_DirectFB_mouse.c index 365c6de35..3ec5e61f1 100644 --- a/src/video/directfb/SDL_DirectFB_mouse.c +++ b/src/video/directfb/SDL_DirectFB_mouse.c @@ -68,7 +68,7 @@ DirectFB_InitMouse(_THIS) SDL_DFB_DEVICEDATA(_this); devdata->num_mice = 0; - if (LINUX_INPUT_SUPPORT) { + if (devdata->use_linux_input) { /* try non-core devices first */ id_mask = 0xF0; devdata->dfb->EnumInputDevices(devdata->dfb, EnumMice, devdata); @@ -100,7 +100,7 @@ DirectFB_QuitMouse(_THIS) { SDL_DFB_DEVICEDATA(_this); - if (LINUX_INPUT_SUPPORT) { + if (devdata->use_linux_input) { SDL_MouseQuit(); } else { SDL_DelMouse(0); diff --git a/src/video/directfb/SDL_DirectFB_opengl.c b/src/video/directfb/SDL_DirectFB_opengl.c index 552ae8896..25a289a19 100644 --- a/src/video/directfb/SDL_DirectFB_opengl.c +++ b/src/video/directfb/SDL_DirectFB_opengl.c @@ -175,6 +175,10 @@ DirectFB_GL_CreateContext(_THIS, SDL_Window * window) SDL_DFB_CHECKERR(windata->surface-> GetGL(windata->surface, &context->context)); + + if (!context->context) + return NULL; + SDL_DFB_CHECKERR(context->context->Unlock(context->context)); context->next = _this->gl_data->firstgl; diff --git a/src/video/directfb/SDL_DirectFB_video.c b/src/video/directfb/SDL_DirectFB_video.c index e0740c508..97978077a 100644 --- a/src/video/directfb/SDL_DirectFB_video.c +++ b/src/video/directfb/SDL_DirectFB_video.c @@ -46,6 +46,8 @@ #include "SDL_DirectFB_render.h" #include "SDL_DirectFB_mouse.h" +#include "SDL_DirectFB_dyn.h" + /* Initialization/Query functions */ static int DirectFB_VideoInit(_THIS); static void DirectFB_VideoQuit(_THIS); @@ -66,14 +68,18 @@ VideoBootStrap DirectFB_bootstrap = { static int DirectFB_Available(void) { + if (!SDL_DirectFB_LoadLibrary()) + return 0; + SDL_DirectFB_UnLoadLibrary(); return 1; } static void DirectFB_DeleteDevice(SDL_VideoDevice * device) { - SDL_free(device->driverdata); - SDL_free(device); + SDL_DirectFB_UnLoadLibrary(); + SDL_DFB_FREE(device->driverdata); + SDL_DFB_FREE(device); } static SDL_VideoDevice * @@ -81,6 +87,9 @@ DirectFB_CreateDevice(int devindex) { SDL_VideoDevice *device; + if (!SDL_DirectFB_LoadLibrary()) + return NULL; + /* Initialize all variables that we clean on shutdown */ SDL_DFB_CALLOC(device, 1, sizeof(SDL_VideoDevice)); @@ -140,22 +149,47 @@ static int DirectFB_VideoInit(_THIS) { IDirectFB *dfb = NULL; - DFB_DeviceData *devdata; + DFB_DeviceData *devdata = NULL; char *stemp; DFBResult ret; + SDL_DFB_CALLOC(devdata, 1, sizeof(*devdata)); + SDL_DFB_CHECKERR(DirectFBInit(NULL, NULL)); - SDL_DFB_CHECKERR(DirectFBCreate(&dfb)); - SDL_DFB_CALLOC(devdata, 1, sizeof(*devdata)); + /* avoid switching to the framebuffer when we + * are running X11 */ + stemp = getenv(DFBENV_USE_X11_CHECK); + if (stemp) + ret = atoi(stemp); + else + ret = 1; + + if (ret) { + if (getenv("DISPLAY")) + DirectFBSetOption("system", "x11"); + else + DirectFBSetOption("disable-module", "x11input"); + } + + devdata->use_linux_input = 1; /* default: on */ + stemp = getenv(DFBENV_USE_LINUX_INPUT); + if (stemp) + devdata->use_linux_input = atoi(stemp); + + if (!devdata->use_linux_input) + DirectFBSetOption("disable-module", "linux_input"); + + SDL_DFB_CHECKERR(DirectFBCreate(&dfb)); devdata->use_yuv_underlays = 0; /* default: off */ stemp = getenv(DFBENV_USE_YUV_UNDERLAY); if (stemp) devdata->use_yuv_underlays = atoi(stemp); + /* Create global Eventbuffer for axis events */ - if (LINUX_INPUT_SUPPORT) { + if (devdata->use_linux_input) { SDL_DFB_CHECKERR(dfb-> CreateInputEventBuffer(dfb, DICAPS_ALL, DFB_TRUE, &devdata->events)); @@ -187,6 +221,7 @@ DirectFB_VideoInit(_THIS) error: + SDL_DFB_FREE(devdata); SDL_DFB_RELEASE(dfb); return -1; } @@ -202,7 +237,6 @@ DirectFB_VideoQuit(_THIS) SDL_DFB_RELEASE(devdata->events); SDL_DFB_RELEASE(devdata->dfb); - SDL_DFB_FREE(_this->driverdata); #if SDL_DIRECTFB_OPENGL DirectFB_GL_Shutdown(_this); diff --git a/src/video/directfb/SDL_DirectFB_video.h b/src/video/directfb/SDL_DirectFB_video.h index 452fedd1c..ba4b4b28b 100644 --- a/src/video/directfb/SDL_DirectFB_video.h +++ b/src/video/directfb/SDL_DirectFB_video.h @@ -31,8 +31,6 @@ #include "SDL_mouse.h" -#define LINUX_INPUT_SUPPORT 1 - #define DEBUG 0 #define LOG_CHANNEL stdout @@ -59,8 +57,10 @@ #include "SDL_DirectFB_opengl.h" #include "SDL_DirectFB_window.h" -#define DFBENV_USE_YUV_UNDERLAY "SDL_DIRECTFB_YUV_UNDERLAY" -#define DFBENV_USE_YUV_DIRECT "SDL_DIRECTFB_YUV_DIRECT" +#define DFBENV_USE_YUV_UNDERLAY "SDL_DIRECTFB_YUV_UNDERLAY" /* Default: off */ +#define DFBENV_USE_YUV_DIRECT "SDL_DIRECTFB_YUV_DIRECT" /* Default: off */ +#define DFBENV_USE_X11_CHECK "SDL_DIRECTFB_X11_CHECK" /* Default: on */ +#define DFBENV_USE_LINUX_INPUT "SDL_DIRECTFB_LINUX_INPUT" /* Default: on */ #define SDL_DFB_RELEASE(x) do { if ( x ) { x->Release(x); x = NULL; } } while (0) #define SDL_DFB_FREE(x) do { if ( x ) { SDL_free(x); x = NULL; } } while (0) @@ -137,6 +137,7 @@ struct _DFB_DeviceData DFB_WindowData *firstwin; int use_yuv_underlays; + int use_linux_input; /* OpenGL */ void (*glFinish) (void);