diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..c0aaf01d3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.swp +aclocal.m4 +*.cache/ diff --git a/configure b/configure index cdb12bd02..bbfad611a 100755 --- a/configure +++ b/configure @@ -670,8 +670,6 @@ X_LIBS X_PRE_LIBS X_CFLAGS XMKMF -RPI_LIBS -RPI_CFLAGS FUSIONSOUND_LIBS FUSIONSOUND_CFLAGS ARTSCONFIG @@ -768,6 +766,7 @@ infodir docdir oldincludedir includedir +runstatedir localstatedir sharedstatedir sysconfdir @@ -925,8 +924,6 @@ PULSEAUDIO_CFLAGS PULSEAUDIO_LIBS FUSIONSOUND_CFLAGS FUSIONSOUND_LIBS -RPI_CFLAGS -RPI_LIBS XMKMF DIRECTFB_CFLAGS DIRECTFB_LIBS @@ -978,6 +975,7 @@ datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' +runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE}' @@ -1230,6 +1228,15 @@ do | -silent | --silent | --silen | --sile | --sil) silent=yes ;; + -runstatedir | --runstatedir | --runstatedi | --runstated \ + | --runstate | --runstat | --runsta | --runst | --runs \ + | --run | --ru | --r) + ac_prev=runstatedir ;; + -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ + | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ + | --run=* | --ru=* | --r=*) + runstatedir=$ac_optarg ;; + -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ @@ -1367,7 +1374,7 @@ fi for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ - libdir localedir mandir + libdir localedir mandir runstatedir do eval ac_val=\$$ac_var # Remove trailing slashes. @@ -1520,6 +1527,7 @@ Fine tuning of the installation directories: --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] @@ -1737,8 +1745,6 @@ Some influential environment variables: C compiler flags for FUSIONSOUND, overriding pkg-config FUSIONSOUND_LIBS linker flags for FUSIONSOUND, overriding pkg-config - RPI_CFLAGS C compiler flags for RPI, overriding pkg-config - RPI_LIBS linker flags for RPI, overriding pkg-config XMKMF Path to xmkmf, Makefile generator for X Window System DIRECTFB_CFLAGS C compiler flags for DIRECTFB, overriding pkg-config @@ -19937,135 +19943,46 @@ else enable_video_rpi=yes fi - if test x$enable_video = xyes -a x$enable_video_rpi = xyes; then - -pkg_failed=no -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for RPI" >&5 -$as_echo_n "checking for RPI... " >&6; } - -if test -n "$RPI_CFLAGS"; then - pkg_cv_RPI_CFLAGS="$RPI_CFLAGS" - elif test -n "$PKG_CONFIG"; then - if test -n "$PKG_CONFIG" && \ - { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"bcm_host brcmegl\""; } >&5 - ($PKG_CONFIG --exists --print-errors "bcm_host brcmegl") 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; }; then - pkg_cv_RPI_CFLAGS=`$PKG_CONFIG --cflags "bcm_host brcmegl" 2>/dev/null` + if test x$enable_video = xyes -a x$enable_video_rpi = xyes && \ + test x$have_loadso = xyes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for /opt/vc/include/bcm_host.h" >&5 +$as_echo_n "checking for /opt/vc/include/bcm_host.h... " >&6; } +if ${ac_cv_file__opt_vc_include_bcm_host_h+:} false; then : + $as_echo_n "(cached) " >&6 else - pkg_failed=yes -fi - else - pkg_failed=untried -fi -if test -n "$RPI_LIBS"; then - pkg_cv_RPI_LIBS="$RPI_LIBS" - elif test -n "$PKG_CONFIG"; then - if test -n "$PKG_CONFIG" && \ - { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"bcm_host brcmegl\""; } >&5 - ($PKG_CONFIG --exists --print-errors "bcm_host brcmegl") 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; }; then - pkg_cv_RPI_LIBS=`$PKG_CONFIG --libs "bcm_host brcmegl" 2>/dev/null` + test "$cross_compiling" = yes && + as_fn_error $? "cannot check for file existence when cross compiling" "$LINENO" 5 +if test -r "/opt/vc/include/bcm_host.h"; then + ac_cv_file__opt_vc_include_bcm_host_h=yes else - pkg_failed=yes + ac_cv_file__opt_vc_include_bcm_host_h=no fi - else - pkg_failed=untried fi - - - -if test $pkg_failed = yes; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - -if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then - _pkg_short_errors_supported=yes +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_file__opt_vc_include_bcm_host_h" >&5 +$as_echo "$ac_cv_file__opt_vc_include_bcm_host_h" >&6; } +if test "x$ac_cv_file__opt_vc_include_bcm_host_h" = xyes; then : + have_video_rpi=yes else - _pkg_short_errors_supported=no -fi - if test $_pkg_short_errors_supported = yes; then - RPI_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "bcm_host brcmegl" 2>&1` - else - RPI_PKG_ERRORS=`$PKG_CONFIG --print-errors "bcm_host brcmegl" 2>&1` - fi - # Put the nasty error message in config.log where it belongs - echo "$RPI_PKG_ERRORS" >&5 - - video_rpi=no -elif test $pkg_failed = untried; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - video_rpi=no -else - RPI_CFLAGS=$pkg_cv_RPI_CFLAGS - RPI_LIBS=$pkg_cv_RPI_LIBS - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - video_rpi=yes + have_video_rpi=no fi - if test x$video_rpi = xno; then - if test x$ARCH = xnetbsd; then - RPI_CFLAGS="-I/usr/pkg/include -I/usr/pkg/include/interface/vcos/pthreads -I/usr/pkg/include/interface/vmcs_host/linux" - RPI_LIBS="-Wl,-R/usr/pkg/lib -L/usr/pkg/lib -lbcm_host" - else - RPI_CFLAGS="-I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux" - RPI_LIBS="-Wl,-rpath,/opt/vc/lib -L/opt/vc/lib -lbcm_host" - fi - fi + fi - # Save the original compiler flags and libraries - ac_save_cflags="$CFLAGS"; ac_save_libs="$LIBS" - - # Add the Raspberry Pi compiler flags and libraries - CFLAGS="$CFLAGS $RPI_CFLAGS"; LIBS="$LIBS $RPI_LIBS" - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Raspberry Pi" >&5 -$as_echo_n "checking for Raspberry Pi... " >&6; } - have_video_rpi=no - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - - #include - -int -main () -{ - - bcm_host_init(); - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - - have_video_rpi=yes - -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_video_rpi" >&5 -$as_echo "$have_video_rpi" >&6; } - - # Restore the compiler flags and libraries - CFLAGS="$ac_save_cflags"; LIBS="$ac_save_libs" - - if test x$have_video_rpi = xyes; then - CFLAGS="$CFLAGS $RPI_CFLAGS" - SDL_CFLAGS="$SDL_CFLAGS $RPI_CFLAGS" - EXTRA_CFLAGS="$EXTRA_CFLAGS $RPI_CFLAGS" - EXTRA_LDFLAGS="$EXTRA_LDFLAGS $RPI_LIBS" - SOURCES="$SOURCES $srcdir/src/video/raspberry/*.c" + if test x$have_video_rpi = xyes; then + RPI_CFLAGS="-I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux" + CFLAGS="$CFLAGS $RPI_CFLAGS" + SDL_CFLAGS="$SDL_CFLAGS $RPI_CFLAGS" + EXTRA_CFLAGS="$EXTRA_CFLAGS $RPI_CFLAGS" + SOURCES="$SOURCES $srcdir/src/video/raspberry/*.c" $as_echo "#define SDL_VIDEO_DRIVER_RPI 1" >>confdefs.h - SUMMARY_video="${SUMMARY_video} rpi" - fi + +cat >>confdefs.h <<_ACEOF +#define SDL_VIDEO_DRIVER_RPI_DYNAMIC "libbcm_host.so" +_ACEOF + + SUMMARY_video="${SUMMARY_video} rpi(dynamic)" fi } @@ -20178,8 +20095,6 @@ ac_x_header_dirs=' /usr/local/include/X11R5 /usr/local/include/X11R4 -/opt/X11/include - /usr/X386/include /usr/x386/include /usr/XFree86/include/X11 diff --git a/configure.ac b/configure.ac index b7e519b8f..ce961cae6 100644 --- a/configure.ac +++ b/configure.ac @@ -1635,49 +1635,20 @@ CheckRPI() AC_ARG_ENABLE(video-rpi, AS_HELP_STRING([--enable-video-rpi], [use Raspberry Pi video driver [[default=yes]]]), , enable_video_rpi=yes) - if test x$enable_video = xyes -a x$enable_video_rpi = xyes; then - PKG_CHECK_MODULES([RPI], [bcm_host brcmegl], video_rpi=yes, video_rpi=no) + if test x$enable_video = xyes -a x$enable_video_rpi = xyes && \ + test x$have_loadso = xyes; then + AC_CHECK_FILE(/opt/vc/include/bcm_host.h, have_video_rpi=yes, have_video_rpi=no) + fi - if test x$video_rpi = xno; then - if test x$ARCH = xnetbsd; then - RPI_CFLAGS="-I/usr/pkg/include -I/usr/pkg/include/interface/vcos/pthreads -I/usr/pkg/include/interface/vmcs_host/linux" - RPI_LIBS="-Wl,-R/usr/pkg/lib -L/usr/pkg/lib -lbcm_host" - else - RPI_CFLAGS="-I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux" - RPI_LIBS="-Wl,-rpath,/opt/vc/lib -L/opt/vc/lib -lbcm_host" - fi - fi - - # Save the original compiler flags and libraries - ac_save_cflags="$CFLAGS"; ac_save_libs="$LIBS" - - # Add the Raspberry Pi compiler flags and libraries - CFLAGS="$CFLAGS $RPI_CFLAGS"; LIBS="$LIBS $RPI_LIBS" - - AC_MSG_CHECKING(for Raspberry Pi) - have_video_rpi=no - AC_TRY_LINK([ - #include - ],[ - bcm_host_init(); - ],[ - have_video_rpi=yes - ],[ - ]) - AC_MSG_RESULT($have_video_rpi) - - # Restore the compiler flags and libraries - CFLAGS="$ac_save_cflags"; LIBS="$ac_save_libs" - - if test x$have_video_rpi = xyes; then - CFLAGS="$CFLAGS $RPI_CFLAGS" - SDL_CFLAGS="$SDL_CFLAGS $RPI_CFLAGS" - EXTRA_CFLAGS="$EXTRA_CFLAGS $RPI_CFLAGS" - EXTRA_LDFLAGS="$EXTRA_LDFLAGS $RPI_LIBS" - SOURCES="$SOURCES $srcdir/src/video/raspberry/*.c" - AC_DEFINE(SDL_VIDEO_DRIVER_RPI, 1, [ ]) - SUMMARY_video="${SUMMARY_video} rpi" - fi + if test x$have_video_rpi = xyes; then + RPI_CFLAGS="-I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux" + CFLAGS="$CFLAGS $RPI_CFLAGS" + SDL_CFLAGS="$SDL_CFLAGS $RPI_CFLAGS" + EXTRA_CFLAGS="$EXTRA_CFLAGS $RPI_CFLAGS" + SOURCES="$SOURCES $srcdir/src/video/raspberry/*.c" + AC_DEFINE(SDL_VIDEO_DRIVER_RPI, 1, [ ]) + AC_DEFINE_UNQUOTED(SDL_VIDEO_DRIVER_RPI_DYNAMIC, "libbcm_host.so", [ ]) + SUMMARY_video="${SUMMARY_video} rpi(dynamic)" fi } diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in index 3a2a7149d..90acf1211 100644 --- a/include/SDL_config.h.in +++ b/include/SDL_config.h.in @@ -353,6 +353,7 @@ #undef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON #undef SDL_VIDEO_DRIVER_X11 #undef SDL_VIDEO_DRIVER_RPI +#undef SDL_VIDEO_DRIVER_RPI_DYNAMIC #undef SDL_VIDEO_DRIVER_KMSDRM #undef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC #undef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c index 5ea732fbe..ee31e75a6 100644 --- a/src/video/SDL_egl.c +++ b/src/video/SDL_egl.c @@ -29,6 +29,9 @@ #include #include "../core/android/SDL_android.h" #endif +#if SDL_VIDEO_DRIVER_RPI +#include +#endif #include "SDL_sysvideo.h" #include "SDL_egl_c.h" diff --git a/src/video/raspberry/SDL_rpidyn.c b/src/video/raspberry/SDL_rpidyn.c new file mode 100644 index 000000000..87dc36c45 --- /dev/null +++ b/src/video/raspberry/SDL_rpidyn.c @@ -0,0 +1,158 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2021 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ +#include "../../SDL_internal.h" + +#if SDL_VIDEO_DRIVER_RPI + +#define DEBUG_DYNAMIC_RPI 0 + +#include "SDL_rpidyn.h" + +#if DEBUG_DYNAMIC_RPI +#include +#endif + +#ifdef SDL_VIDEO_DRIVER_RPI_DYNAMIC + +#include "SDL_name.h" +#include "SDL_loadso.h" + +typedef struct +{ + void *lib; + const char *libname; +} rpidynlib; + +static rpidynlib rpilibs[] = { + {NULL, SDL_VIDEO_DRIVER_RPI_DYNAMIC} +}; + +static void * +RPI_GetSym(const char *fnname, int *pHasModule) +{ + int i; + void *fn = NULL; + for (i = 0; i < SDL_TABLESIZE(rpilibs); i++) { + if (rpilibs[i].lib != NULL) { + fn = SDL_LoadFunction(rpilibs[i].lib, fnname); + if (fn != NULL) + break; + } + } + +#if DEBUG_DYNAMIC_RPI + if (fn != NULL) + printf("RPI: Found '%s' in %s (%p)\n", fnname, rpilibs[i].libname, fn); + else + printf("RPI: Symbol '%s' NOT FOUND!\n", fnname); +#endif + + if (fn == NULL) + *pHasModule = 0; /* kill this module. */ + + return fn; +} + +#endif /* SDL_VIDEO_DRIVER_RPI_DYNAMIC */ + +/* Define all the function pointers and wrappers... */ +#define SDL_RPI_SYM(rc,fn,params,args,ret) SDL_DYNRPIFN_##fn RPI_##fn = NULL; +#include "SDL_rpisym.h" + +/* These SDL_RPI_HAVE_* flags are here whether you have dynamic RPI or not. */ +#define SDL_RPI_MODULE(modname) int SDL_RPI_HAVE_##modname = 0; +#include "SDL_rpisym.h" + +static int rpi_load_refcount = 0; + +void +SDL_RPI_UnloadSymbols(void) +{ + /* Don't actually unload if more than one module is using the libs... */ + if (rpi_load_refcount > 0) { + if (--rpi_load_refcount == 0) { + int i; + + /* set all the function pointers to NULL. */ +#define SDL_RPI_MODULE(modname) SDL_RPI_HAVE_##modname = 0; +#define SDL_RPI_SYM(rc,fn,params,args,ret) RPI_##fn = NULL; +#include "SDL_rpisym.h" + +#ifdef SDL_VIDEO_DRIVER_RPI_DYNAMIC + for (i = 0; i < SDL_TABLESIZE(rpilibs); i++) { + if (rpilibs[i].lib != NULL) { + SDL_UnloadObject(rpilibs[i].lib); + rpilibs[i].lib = NULL; + } + } +#endif + } + } +} + +/* returns non-zero if all needed symbols were loaded. */ +int +SDL_RPI_LoadSymbols(void) +{ + int rc = 1; /* always succeed if not using Dynamic RPI stuff. */ + + /* deal with multiple modules (dga, rpi, etc) needing these symbols... */ + if (rpi_load_refcount++ == 0) { +#ifdef SDL_VIDEO_DRIVER_RPI_DYNAMIC + int i; + int *thismod = NULL; + for (i = 0; i < SDL_TABLESIZE(rpilibs); i++) { + if (rpilibs[i].libname != NULL) { + rpilibs[i].lib = SDL_LoadObject(rpilibs[i].libname); + } + } + +#define SDL_RPI_MODULE(modname) SDL_RPI_HAVE_##modname = 1; /* default yes */ +#include "SDL_rpisym.h" + +#define SDL_RPI_MODULE(modname) thismod = &SDL_RPI_HAVE_##modname; +#define SDL_RPI_SYM(a,fn,x,y,z) RPI_##fn = (SDL_DYNRPIFN_##fn) RPI_GetSym(#fn,thismod); +#include "SDL_rpisym.h" + + if (SDL_RPI_HAVE_BCM) { + /* all required symbols loaded. */ + SDL_ClearError(); + } else { + /* in case something got loaded... */ + SDL_RPI_UnloadSymbols(); + rc = 0; + } + +#else /* no dynamic RPI */ + +#define SDL_RPI_MODULE(modname) SDL_RPI_HAVE_##modname = 1; /* default yes */ +#define SDL_RPI_SYM(a,fn,x,y,z) RPI_##fn = (SDL_DYNRPIFN_##fn) fn; +#include "SDL_rpisym.h" + +#endif + } + + return rc; +} + +#endif /* SDL_VIDEO_DRIVER_RPI */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/raspberry/SDL_rpidyn.h b/src/video/raspberry/SDL_rpidyn.h new file mode 100644 index 000000000..988214bfb --- /dev/null +++ b/src/video/raspberry/SDL_rpidyn.h @@ -0,0 +1,51 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2021 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ +#include "../../SDL_internal.h" + +#ifndef SDL_rpidyn_h_ +#define SDL_rpidyn_h_ + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +int SDL_RPI_LoadSymbols(void); +void SDL_RPI_UnloadSymbols(void); + +/* Declare all the function pointers and wrappers... */ +#define SDL_RPI_SYM(rc,fn,params,args,ret) \ + typedef rc (*SDL_DYNRPIFN_##fn) params; \ + extern SDL_DYNRPIFN_##fn RPI_##fn; +#include "SDL_rpisym.h" + +/* These SDL_RPI_HAVE_* flags are here whether you have dynamic RPI or not. */ +#define SDL_RPI_MODULE(modname) extern int SDL_RPI_HAVE_##modname; +#include "SDL_rpisym.h" + +#ifdef __cplusplus +} +#endif + +#endif /* !defined SDL_rpidyn_h_ */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/raspberry/SDL_rpimouse.c b/src/video/raspberry/SDL_rpimouse.c index 1ed140420..86c2ec673 100644 --- a/src/video/raspberry/SDL_rpimouse.c +++ b/src/video/raspberry/SDL_rpimouse.c @@ -89,16 +89,16 @@ RPI_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y) curdata->h = surface->h; /* This usage is inspired by Wayland/Weston RPI code, how they figured this out is anyone's guess */ - curdata->resource = vc_dispmanx_resource_create(VC_IMAGE_ARGB8888, surface->w | (surface->pitch << 16), surface->h | (surface->h << 16), &dummy); + curdata->resource = RPI_vc_dispmanx_resource_create(VC_IMAGE_ARGB8888, surface->w | (surface->pitch << 16), surface->h | (surface->h << 16), &dummy); SDL_assert(curdata->resource); - vc_dispmanx_rect_set(&dst_rect, 0, 0, curdata->w, curdata->h); + RPI_vc_dispmanx_rect_set(&dst_rect, 0, 0, curdata->w, curdata->h); /* A note from Weston: * vc_dispmanx_resource_write_data() ignores ifmt, * rect.x, rect.width, and uses stride only for computing * the size of the transfer as rect.height * stride. * Therefore we can only write rows starting at x=0. */ - ret = vc_dispmanx_resource_write_data(curdata->resource, VC_IMAGE_ARGB8888, surface->pitch, surface->pixels, &dst_rect); + ret = RPI_vc_dispmanx_resource_write_data(curdata->resource, VC_IMAGE_ARGB8888, surface->pitch, surface->pixels, &dst_rect); SDL_assert (ret == DISPMANX_SUCCESS); cursor->driverdata = curdata; @@ -131,11 +131,11 @@ RPI_ShowCursor(SDL_Cursor * cursor) if (global_cursor != NULL) { curdata = (RPI_CursorData *) global_cursor->driverdata; if (curdata && curdata->element > DISPMANX_NO_HANDLE) { - update = vc_dispmanx_update_start(0); + update = RPI_vc_dispmanx_update_start(0); SDL_assert(update); - ret = vc_dispmanx_element_remove(update, curdata->element); + ret = RPI_vc_dispmanx_element_remove(update, curdata->element); SDL_assert(ret == DISPMANX_SUCCESS); - ret = vc_dispmanx_update_submit_sync(update); + ret = RPI_vc_dispmanx_update_submit_sync(update); SDL_assert(ret == DISPMANX_SUCCESS); curdata->element = DISPMANX_NO_HANDLE; } @@ -167,10 +167,10 @@ RPI_ShowCursor(SDL_Cursor * cursor) } if (curdata->element == DISPMANX_NO_HANDLE) { - vc_dispmanx_rect_set(&src_rect, 0, 0, curdata->w << 16, curdata->h << 16); - vc_dispmanx_rect_set(&dst_rect, mouse->x - curdata->hot_x, mouse->y - curdata->hot_y, curdata->w, curdata->h); + RPI_vc_dispmanx_rect_set(&src_rect, 0, 0, curdata->w << 16, curdata->h << 16); + RPI_vc_dispmanx_rect_set(&dst_rect, mouse->x - curdata->hot_x, mouse->y - curdata->hot_y, curdata->w, curdata->h); - update = vc_dispmanx_update_start(0); + update = RPI_vc_dispmanx_update_start(0); SDL_assert(update); env = SDL_GetHint(SDL_HINT_RPI_VIDEO_LAYER); @@ -178,7 +178,7 @@ RPI_ShowCursor(SDL_Cursor * cursor) layer = SDL_atoi(env) + 1; } - curdata->element = vc_dispmanx_element_add(update, + curdata->element = RPI_vc_dispmanx_element_add(update, data->dispman_display, layer, &dst_rect, @@ -189,7 +189,7 @@ RPI_ShowCursor(SDL_Cursor * cursor) DISPMANX_NO_HANDLE, // clamp DISPMANX_NO_ROTATE); SDL_assert(curdata->element > DISPMANX_NO_HANDLE); - ret = vc_dispmanx_update_submit_sync(update); + ret = RPI_vc_dispmanx_update_submit_sync(update); SDL_assert(ret == DISPMANX_SUCCESS); } @@ -209,16 +209,16 @@ RPI_FreeCursor(SDL_Cursor * cursor) if (curdata != NULL) { if (curdata->element != DISPMANX_NO_HANDLE) { - update = vc_dispmanx_update_start(0); + update = RPI_vc_dispmanx_update_start(0); SDL_assert(update); - ret = vc_dispmanx_element_remove(update, curdata->element); + ret = RPI_vc_dispmanx_element_remove(update, curdata->element); SDL_assert(ret == DISPMANX_SUCCESS); - ret = vc_dispmanx_update_submit_sync(update); + ret = RPI_vc_dispmanx_update_submit_sync(update); SDL_assert(ret == DISPMANX_SUCCESS); } if (curdata->resource != DISPMANX_NO_HANDLE) { - ret = vc_dispmanx_resource_delete(curdata->resource); + ret = RPI_vc_dispmanx_resource_delete(curdata->resource); SDL_assert(ret == DISPMANX_SUCCESS); } @@ -261,7 +261,7 @@ RPI_WarpMouseGlobal(int x, int y) return 0; } - update = vc_dispmanx_update_start(0); + update = RPI_vc_dispmanx_update_start(0); if (!update) { return 0; } @@ -275,7 +275,7 @@ RPI_WarpMouseGlobal(int x, int y) dst_rect.width = curdata->w; dst_rect.height = curdata->h; - ret = vc_dispmanx_element_change_attributes( + ret = RPI_vc_dispmanx_element_change_attributes( update, curdata->element, 0, @@ -290,7 +290,7 @@ RPI_WarpMouseGlobal(int x, int y) } /* Submit asynchronously, otherwise the peformance suffers a lot */ - ret = vc_dispmanx_update_submit(update, 0, NULL); + ret = RPI_vc_dispmanx_update_submit(update, 0, NULL); if (ret != DISPMANX_SUCCESS) { return SDL_SetError("vc_dispmanx_update_submit() failed"); } @@ -317,7 +317,7 @@ RPI_WarpMouseGlobalGraphicOnly(int x, int y) return 0; } - update = vc_dispmanx_update_start(0); + update = RPI_vc_dispmanx_update_start(0); if (!update) { return 0; } @@ -331,7 +331,7 @@ RPI_WarpMouseGlobalGraphicOnly(int x, int y) dst_rect.width = curdata->w; dst_rect.height = curdata->h; - ret = vc_dispmanx_element_change_attributes( + ret = RPI_vc_dispmanx_element_change_attributes( update, curdata->element, 0, @@ -346,7 +346,7 @@ RPI_WarpMouseGlobalGraphicOnly(int x, int y) } /* Submit asynchronously, otherwise the peformance suffers a lot */ - ret = vc_dispmanx_update_submit(update, 0, NULL); + ret = RPI_vc_dispmanx_update_submit(update, 0, NULL); if (ret != DISPMANX_SUCCESS) { return SDL_SetError("vc_dispmanx_update_submit() failed"); } diff --git a/src/video/raspberry/SDL_rpisym.h b/src/video/raspberry/SDL_rpisym.h new file mode 100644 index 000000000..4594e1b10 --- /dev/null +++ b/src/video/raspberry/SDL_rpisym.h @@ -0,0 +1,57 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2021 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +/* *INDENT-OFF* */ + +#ifndef SDL_RPI_MODULE +#define SDL_RPI_MODULE(modname) +#endif + +#ifndef SDL_RPI_SYM +#define SDL_RPI_SYM(rc,fn,params,args,ret) +#endif + +SDL_RPI_MODULE(BCM) + +SDL_RPI_SYM(void,bcm_host_init,(void),(),return) +SDL_RPI_SYM(int,vc_dispmanx_display_close,(DISPMANX_DISPLAY_HANDLE_T display),(display),return) +SDL_RPI_SYM(DISPMANX_DISPLAY_HANDLE_T,vc_dispmanx_display_open,(uint32_t device),(device),return) +SDL_RPI_SYM(DISPMANX_ELEMENT_HANDLE_T,vc_dispmanx_element_add,(DISPMANX_UPDATE_HANDLE_T update, DISPMANX_DISPLAY_HANDLE_T display, int32_t layer, const VC_RECT_T *dest_rect, DISPMANX_RESOURCE_HANDLE_T src, const VC_RECT_T *src_rect, DISPMANX_PROTECTION_T protection, VC_DISPMANX_ALPHA_T *alpha, DISPMANX_CLAMP_T *clamp, DISPMANX_TRANSFORM_T transform),(update,display,layer,dest_rect,src,src_rect,protection,alpha,clamp,transform),return) +SDL_RPI_SYM(int,vc_dispmanx_element_change_attributes,(DISPMANX_UPDATE_HANDLE_T update, DISPMANX_ELEMENT_HANDLE_T element, uint32_t change_flags, int32_t layer, uint8_t opacity, const VC_RECT_T *dest_rect, const VC_RECT_T *src_rect, DISPMANX_RESOURCE_HANDLE_T mask, DISPMANX_TRANSFORM_T transform),(update,element,change_flags,layer,opacity,dest_rect,src_rect,mask,transform),return) +SDL_RPI_SYM(int,vc_dispmanx_element_remove,(DISPMANX_UPDATE_HANDLE_T update, DISPMANX_ELEMENT_HANDLE_T element),(update,element),return) +SDL_RPI_SYM(int,vc_dispmanx_rect_set,(VC_RECT_T *rect, uint32_t x_offset, uint32_t y_offset, uint32_t width, uint32_t height),(rect,x_offset,y_offset,width,height),return) +SDL_RPI_SYM(DISPMANX_RESOURCE_HANDLE_T,vc_dispmanx_resource_create,(VC_IMAGE_TYPE_T type, uint32_t width, uint32_t height, uint32_t *native_image_handle),(type,width,height,native_image_handle),return) +SDL_RPI_SYM(int,vc_dispmanx_resource_delete,(DISPMANX_RESOURCE_HANDLE_T res),(res),return) +SDL_RPI_SYM(int,vc_dispmanx_resource_write_data,(DISPMANX_RESOURCE_HANDLE_T res, VC_IMAGE_TYPE_T src_type, int src_pitch, void * src_address, const VC_RECT_T * rect),(res,src_type,src_pitch,src_address,rect),return) +SDL_RPI_SYM(DISPMANX_UPDATE_HANDLE_T,vc_dispmanx_update_start,(int32_t priority),(priority),return) +SDL_RPI_SYM(int,vc_dispmanx_update_submit,(DISPMANX_UPDATE_HANDLE_T update, DISPMANX_CALLBACK_FUNC_T cb_func, void *cb_arg),(update,cb_func,cb_arg),return) +SDL_RPI_SYM(int,vc_dispmanx_update_submit_sync,(DISPMANX_UPDATE_HANDLE_T update),(update),return) +SDL_RPI_SYM(int,vc_dispmanx_display_get_info,(DISPMANX_DISPLAY_HANDLE_T display, DISPMANX_MODEINFO_T *pinfo),(display,pinfo),return) +SDL_RPI_SYM(int,vc_dispmanx_vsync_callback,(DISPMANX_DISPLAY_HANDLE_T display, DISPMANX_CALLBACK_FUNC_T cb_func, void *cb_arg),(display,cb_func,cb_arg),return) +SDL_RPI_SYM(int,vc_tv_get_display_state,(TV_DISPLAY_STATE_T *tvstate),(tvstate),return) +SDL_RPI_SYM(int,vc_tv_hdmi_get_property,(HDMI_PROPERTY_PARAM_T *property),(property),return) + +#undef SDL_RPI_MODULE +#undef SDL_RPI_SYM + +/* *INDENT-ON* */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/raspberry/SDL_rpivideo.c b/src/video/raspberry/SDL_rpivideo.c index 44896c22b..cbcca20d3 100644 --- a/src/video/raspberry/SDL_rpivideo.c +++ b/src/video/raspberry/SDL_rpivideo.c @@ -55,18 +55,20 @@ RPI_Destroy(SDL_VideoDevice * device) { SDL_free(device->driverdata); SDL_free(device); + + SDL_RPI_UnloadSymbols(); } static int RPI_GetRefreshRate() { TV_DISPLAY_STATE_T tvstate; - if (vc_tv_get_display_state( &tvstate ) == 0) { + if (RPI_vc_tv_get_display_state( &tvstate ) == 0) { //The width/height parameters are in the same position in the union //for HDMI and SDTV HDMI_PROPERTY_PARAM_T property; property.property = HDMI_PROPERTY_PIXEL_CLOCK_TYPE; - vc_tv_hdmi_get_property(&property); + RPI_vc_tv_hdmi_get_property(&property); return property.param1 == HDMI_PIXEL_CLOCK_TYPE_NTSC ? tvstate.display.hdmi.frame_rate * (1000.0f/1001.0f) : tvstate.display.hdmi.frame_rate; @@ -80,6 +82,10 @@ RPI_Create() SDL_VideoDevice *device; SDL_VideoData *phdata; + if (!SDL_RPI_LoadSymbols()) { + return NULL; + } + /* Initialize SDL_VideoDevice structure */ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); if (device == NULL) { @@ -161,13 +167,13 @@ AddDispManXDisplay(const int display_id) SDL_DisplayMode current_mode; SDL_DisplayData *data; - handle = vc_dispmanx_display_open(display_id); + handle = RPI_vc_dispmanx_display_open(display_id); if (!handle) { return; /* this display isn't available */ } - if (vc_dispmanx_display_get_info(handle, &modeinfo) < 0) { - vc_dispmanx_display_close(handle); + if (RPI_vc_dispmanx_display_get_info(handle, &modeinfo) < 0) { + RPI_vc_dispmanx_display_close(handle); return; } @@ -188,7 +194,7 @@ AddDispManXDisplay(const int display_id) /* Allocate display internal data */ data = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData)); if (data == NULL) { - vc_dispmanx_display_close(handle); + RPI_vc_dispmanx_display_close(handle); return; /* oh well */ } @@ -203,7 +209,7 @@ int RPI_VideoInit(_THIS) { /* Initialize BCM Host */ - bcm_host_init(); + RPI_bcm_host_init(); AddDispManXDisplay(DISPMANX_ID_MAIN_LCD); /* your default display */ AddDispManXDisplay(DISPMANX_ID_FORCE_OTHER); /* an "other" display...maybe DSI-connected screen while HDMI is your main */ @@ -312,8 +318,8 @@ RPI_CreateWindow(_THIS, SDL_Window * window) layer = SDL_atoi(env); } - dispman_update = vc_dispmanx_update_start( 0 ); - wdata->dispman_window.element = vc_dispmanx_element_add (dispman_update, + dispman_update = RPI_vc_dispmanx_update_start( 0 ); + wdata->dispman_window.element = RPI_vc_dispmanx_element_add (dispman_update, displaydata->dispman_display, layer /* layer */, &dst_rect, @@ -325,7 +331,7 @@ RPI_CreateWindow(_THIS, SDL_Window * window) 0 /*transform*/); wdata->dispman_window.width = window->w; wdata->dispman_window.height = window->h; - vc_dispmanx_update_submit_sync(dispman_update); + RPI_vc_dispmanx_update_submit_sync(dispman_update); if (!_this->egl_data) { if (SDL_GL_LoadLibrary(NULL) < 0) { @@ -344,7 +350,7 @@ RPI_CreateWindow(_THIS, SDL_Window * window) wdata->vsync_cond = SDL_CreateCond(); wdata->vsync_cond_mutex = SDL_CreateMutex(); wdata->double_buffer = SDL_TRUE; - vc_dispmanx_vsync_callback(displaydata->dispman_display, RPI_vsync_callback, (void*)wdata); + RPI_vc_dispmanx_vsync_callback(displaydata->dispman_display, RPI_vsync_callback, (void*)wdata); } /* Setup driver data for this window */ @@ -372,7 +378,7 @@ RPI_DestroyWindow(_THIS, SDL_Window * window) SDL_CondWait(data->vsync_cond, data->vsync_cond_mutex); SDL_UnlockMutex(data->vsync_cond_mutex); - vc_dispmanx_vsync_callback(displaydata->dispman_display, NULL, NULL); + RPI_vc_dispmanx_vsync_callback(displaydata->dispman_display, NULL, NULL); SDL_DestroyCond(data->vsync_cond); SDL_DestroyMutex(data->vsync_cond_mutex); diff --git a/src/video/raspberry/SDL_rpivideo.h b/src/video/raspberry/SDL_rpivideo.h index 557201db6..11bc3209c 100644 --- a/src/video/raspberry/SDL_rpivideo.h +++ b/src/video/raspberry/SDL_rpivideo.h @@ -30,6 +30,8 @@ #include "EGL/egl.h" #include "EGL/eglext.h" +#include "SDL_rpidyn.h" + typedef struct SDL_VideoData { uint32_t egl_refcount; /* OpenGL ES reference count */ diff --git a/test/configure b/test/configure index 4faf15c43..f1e9f0843 100755 --- a/test/configure +++ b/test/configure @@ -640,6 +640,7 @@ infodir docdir oldincludedir includedir +runstatedir localstatedir sharedstatedir sysconfdir @@ -720,6 +721,7 @@ datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' +runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE}' @@ -972,6 +974,15 @@ do | -silent | --silent | --silen | --sile | --sil) silent=yes ;; + -runstatedir | --runstatedir | --runstatedi | --runstated \ + | --runstate | --runstat | --runsta | --runst | --runs \ + | --run | --ru | --r) + ac_prev=runstatedir ;; + -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ + | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ + | --run=* | --ru=* | --r=*) + runstatedir=$ac_optarg ;; + -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ @@ -1109,7 +1120,7 @@ fi for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ - libdir localedir mandir + libdir localedir mandir runstatedir do eval ac_val=\$$ac_var # Remove trailing slashes. @@ -1262,6 +1273,7 @@ Fine tuning of the installation directories: --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] @@ -3625,34 +3637,8 @@ else $as_echo_n "(cached) " >&6 else # One or both of the vars are not set, and there is no cached value. -ac_x_includes=no -ac_x_libraries=no -# Do we need to do anything special at all? -ac_save_LIBS=$LIBS -LIBS="-lX11 $LIBS" -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include -int -main () -{ -XrmInitialize () - ; - return 0; -} -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - # We can compile and link X programs with no special options. - ac_x_includes= - ac_x_libraries= -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -LIBS="$ac_save_LIBS" -# If that didn't work, only try xmkmf and filesystem searches -# for native compilation. -if test x"$ac_x_includes" = xno && test "$cross_compiling" = no; then : - rm -f -r conftest.dir +ac_x_includes=no ac_x_libraries=no +rm -f -r conftest.dir if mkdir conftest.dir; then cd conftest.dir cat >Imakefile <<'_ACEOF' @@ -3691,7 +3677,7 @@ _ACEOF rm -f -r conftest.dir fi - # Standard set of common directories for X headers. +# Standard set of common directories for X headers. # Check X11 before X11Rn because it is often a symlink to the current release. ac_x_header_dirs=' /usr/X11/include @@ -3718,8 +3704,6 @@ ac_x_header_dirs=' /usr/local/include/X11R5 /usr/local/include/X11R4 -/opt/X11/include - /usr/X386/include /usr/x386/include /usr/XFree86/include/X11 @@ -3793,17 +3777,15 @@ rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext fi # $ac_x_libraries = no -fi -# Record the results. case $ac_x_includes,$ac_x_libraries in #( - no,* | *,no | *\'*) : + no,* | *,no | *\'*) # Didn't find X, or a directory has "'" in its name. - ac_cv_have_x="have_x=no" ;; #( - *) : + ac_cv_have_x="have_x=no";; #( + *) # Record where we found X for the cache. ac_cv_have_x="have_x=yes\ ac_x_includes='$ac_x_includes'\ - ac_x_libraries='$ac_x_libraries'" ;; + ac_x_libraries='$ac_x_libraries'" esac fi ;; #(