From 272ebb8efb786a06091357a673b1b274cf4cb6e2 Mon Sep 17 00:00:00 2001 From: Gabriel Jacobo Date: Thu, 9 Jan 2014 13:56:21 -0300 Subject: [PATCH] Dynamic loading support for Wayland --- configure | 70 ++++++++- configure.in | 50 +++++- include/SDL_config.h.in | 4 + src/video/wayland/SDL_waylanddyn.c | 195 ++++++++++++++++++++++++ src/video/wayland/SDL_waylanddyn.h | 103 +++++++++++++ src/video/wayland/SDL_waylandevents.c | 28 ++-- src/video/wayland/SDL_waylandevents_c.h | 2 +- src/video/wayland/SDL_waylandmouse.c | 33 ++-- src/video/wayland/SDL_waylandmouse.h | 2 +- src/video/wayland/SDL_waylandopengles.c | 13 +- src/video/wayland/SDL_waylandopengles.h | 2 +- src/video/wayland/SDL_waylandsym.h | 102 +++++++++++++ src/video/wayland/SDL_waylandtouch.c | 13 +- src/video/wayland/SDL_waylandtouch.h | 37 ++--- src/video/wayland/SDL_waylandvideo.c | 76 ++++++--- src/video/wayland/SDL_waylandvideo.h | 13 +- src/video/wayland/SDL_waylandwindow.c | 18 +-- src/video/wayland/SDL_waylandwindow.h | 2 +- 18 files changed, 654 insertions(+), 109 deletions(-) create mode 100644 src/video/wayland/SDL_waylanddyn.c create mode 100644 src/video/wayland/SDL_waylanddyn.h create mode 100644 src/video/wayland/SDL_waylandsym.h diff --git a/configure b/configure index a5ce2e388b582..6fcddc3c77345 100755 --- a/configure +++ b/configure @@ -819,6 +819,7 @@ enable_diskaudio enable_dummyaudio enable_video_wayland enable_video_wayland_qt_touch +enable_wayland_shared enable_video_x11 with_x enable_x11_shared @@ -1538,6 +1539,7 @@ Optional Features: --enable-video-wayland-qt-touch QtWayland server support for Wayland video driver [[default=yes]] + --enable-wayland-shared dynamically load Wayland support [[default=maybe]] --enable-video-x11 use X11 video driver [[default=yes]] --enable-x11-shared dynamically load X11 support [[default=maybe]] --enable-video-x11-xcursor @@ -18705,8 +18707,8 @@ $as_echo_n "checking for Wayland support... " >&6; } video_wayland=no if test x$PKG_CONFIG != xno; then if $PKG_CONFIG --exists wayland-client wayland-egl wayland-cursor egl xkbcommon ; then - WAYLAND_CFLAGS=`$PKG_CONFIG --cflags wayland-client wayland-egl wayland-cursor egl xkbcommon` - WAYLAND_LIBS=`$PKG_CONFIG --libs wayland-client wayland-egl wayland-cursor egl xkbcommon` + WAYLAND_CFLAGS=`$PKG_CONFIG --cflags wayland-client wayland-egl wayland-cursor xkbcommon` + WAYLAND_LIBS=`$PKG_CONFIG --libs wayland-client wayland-egl wayland-cursor xkbcommon` video_wayland=yes fi fi @@ -18724,7 +18726,69 @@ $as_echo "#define SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH 1" >>confdefs.h fi SOURCES="$SOURCES $srcdir/src/video/wayland/*.c" EXTRA_CFLAGS="$EXTRA_CFLAGS $WAYLAND_CFLAGS" - EXTRA_LDFLAGS="$EXTRA_LDFLAGS $WAYLAND_LIBS" + # Check whether --enable-wayland-shared was given. +if test "${enable_wayland_shared+set}" = set; then : + enableval=$enable_wayland_shared; +else + enable_wayland_shared=maybe +fi + + + case "$host" in + *) + wayland_client_lib=`find_lib "libwayland-client.so.*" "$WAYLAND_LIBS" | sed 's/.*\/\(.*\)/\1/; q'` + wayland_egl_lib=`find_lib "libwayland-egl.so.*" "$WAYLAND_LIBS" | sed 's/.*\/\(.*\)/\1/; q'` + if test x$wayland_egl_lib = x; then + wayland_egl_lib=`find_lib "mesa-egl/libwayland-egl.so.*" "$WAYLAND_LIBS" | sed 's/.*\/\(.*\)/\1/; q'` + fi + wayland_cursor_lib=`find_lib "libwayland-cursor.so.*" "$WAYLAND_LIBS" | sed 's/.*\/\(.*\)/\1/; q'` + xkbcommon_lib=`find_lib "libxkbcommon.so.*" "$WAYLAND_LIBS" | sed 's/.*\/\(.*\)/\1/; q'` + ;; + esac + + if test x$enable_wayland_shared = xmaybe; then + enable_wayland_shared=yes + fi + if test x$have_loadso != xyes && \ + test x$enable_wayland_shared = xyes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: You must have SDL_LoadObject() support for dynamic WAYLAND loading" >&5 +$as_echo "$as_me: WARNING: You must have SDL_LoadObject() support for dynamic WAYLAND loading" >&2;} + enable_wayland_shared=no + fi + if test x$have_loadso = xyes && \ + test x$enable_wayland_shared = xyes && \ + test x$wayland_client_lib != x && \ + test x$wayland_egl_lib != x && \ + test x$wayland_cursor_lib != x && \ + test x$xkbcommon_lib != x; then + echo "-- dynamic libwayland-client -> $wayland_client_lib" + echo "-- dynamic libwayland-egl -> $wayland_egl_lib" + echo "-- dynamic libwayland-cursor -> $wayland_cursor_lib" + echo "-- dynamic xkbcommon -> $xkbcommon_lib" + +cat >>confdefs.h <<_ACEOF +#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC "$wayland_client_lib" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL "$wayland_egl_lib" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR "$wayland_cursor_lib" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON "$xkbcommon_lib" +_ACEOF + + else + enable_wayland_shared=no + EXTRA_LDFLAGS="$EXTRA_LDFLAGS $WAYLAND_LIBS" + fi have_video=yes fi fi diff --git a/configure.in b/configure.in index 17f5d187c56e8..27eadba305191 100644 --- a/configure.in +++ b/configure.in @@ -1133,8 +1133,8 @@ AC_HELP_STRING([--enable-video-wayland-qt-touch], [QtWayland server support for video_wayland=no if test x$PKG_CONFIG != xno; then if $PKG_CONFIG --exists wayland-client wayland-egl wayland-cursor egl xkbcommon ; then - WAYLAND_CFLAGS=`$PKG_CONFIG --cflags wayland-client wayland-egl wayland-cursor egl xkbcommon` - WAYLAND_LIBS=`$PKG_CONFIG --libs wayland-client wayland-egl wayland-cursor egl xkbcommon` + WAYLAND_CFLAGS=`$PKG_CONFIG --cflags wayland-client wayland-egl wayland-cursor xkbcommon` + WAYLAND_LIBS=`$PKG_CONFIG --libs wayland-client wayland-egl wayland-cursor xkbcommon` video_wayland=yes fi fi @@ -1147,8 +1147,50 @@ AC_HELP_STRING([--enable-video-wayland-qt-touch], [QtWayland server support for fi SOURCES="$SOURCES $srcdir/src/video/wayland/*.c" EXTRA_CFLAGS="$EXTRA_CFLAGS $WAYLAND_CFLAGS" - dnl FIXME do dynamic loading code here. - EXTRA_LDFLAGS="$EXTRA_LDFLAGS $WAYLAND_LIBS" + AC_ARG_ENABLE(wayland-shared, +AC_HELP_STRING([--enable-wayland-shared], [dynamically load Wayland support [[default=maybe]]]), + , enable_wayland_shared=maybe) + + dnl FIXME: Do BSD and OS X need special cases? + case "$host" in + *) + wayland_client_lib=[`find_lib "libwayland-client.so.*" "$WAYLAND_LIBS" | sed 's/.*\/\(.*\)/\1/; q'`] + wayland_egl_lib=[`find_lib "libwayland-egl.so.*" "$WAYLAND_LIBS" | sed 's/.*\/\(.*\)/\1/; q'`] + if test x$wayland_egl_lib = x; then + dnl This works in Ubuntu 13.10, maybe others + wayland_egl_lib=[`find_lib "mesa-egl/libwayland-egl.so.*" "$WAYLAND_LIBS" | sed 's/.*\/\(.*\)/\1/; q'`] + fi + wayland_cursor_lib=[`find_lib "libwayland-cursor.so.*" "$WAYLAND_LIBS" | sed 's/.*\/\(.*\)/\1/; q'`] + xkbcommon_lib=[`find_lib "libxkbcommon.so.*" "$WAYLAND_LIBS" | sed 's/.*\/\(.*\)/\1/; q'`] + ;; + esac + + if test x$enable_wayland_shared = xmaybe; then + enable_wayland_shared=yes + fi + if test x$have_loadso != xyes && \ + test x$enable_wayland_shared = xyes; then + AC_MSG_WARN([You must have SDL_LoadObject() support for dynamic WAYLAND loading]) + enable_wayland_shared=no + fi + if test x$have_loadso = xyes && \ + test x$enable_wayland_shared = xyes && \ + test x$wayland_client_lib != x && \ + test x$wayland_egl_lib != x && \ + test x$wayland_cursor_lib != x && \ + test x$xkbcommon_lib != x; then + echo "-- dynamic libwayland-client -> $wayland_client_lib" + echo "-- dynamic libwayland-egl -> $wayland_egl_lib" + echo "-- dynamic libwayland-cursor -> $wayland_cursor_lib" + echo "-- dynamic xkbcommon -> $xkbcommon_lib" + AC_DEFINE_UNQUOTED(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC, "$wayland_client_lib", [ ]) + AC_DEFINE_UNQUOTED(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL, "$wayland_egl_lib", [ ]) + AC_DEFINE_UNQUOTED(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR, "$wayland_cursor_lib", [ ]) + AC_DEFINE_UNQUOTED(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON, "$xkbcommon_lib", [ ]) + else + enable_wayland_shared=no + EXTRA_LDFLAGS="$EXTRA_LDFLAGS $WAYLAND_LIBS" + fi have_video=yes fi fi diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in index e96bdfaa158e8..eb7b4b9696cfb 100644 --- a/include/SDL_config.h.in +++ b/include/SDL_config.h.in @@ -263,6 +263,10 @@ #undef SDL_VIDEO_DRIVER_WINDOWS #undef SDL_VIDEO_DRIVER_WAYLAND #undef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH +#undef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC +#undef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL +#undef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR +#undef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON #undef SDL_VIDEO_DRIVER_X11 #undef SDL_VIDEO_DRIVER_RPI #undef SDL_VIDEO_DRIVER_X11_DYNAMIC diff --git a/src/video/wayland/SDL_waylanddyn.c b/src/video/wayland/SDL_waylanddyn.c new file mode 100644 index 0000000000000..c2ee8d84e4323 --- /dev/null +++ b/src/video/wayland/SDL_waylanddyn.c @@ -0,0 +1,195 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 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_WAYLAND + +#define DEBUG_DYNAMIC_WAYLAND 0 + +#include "SDL_waylanddyn.h" + +#if DEBUG_DYNAMIC_WAYLAND +#include "SDL_log.h" +#endif + +#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC + +#include "SDL_name.h" +#include "SDL_loadso.h" + +typedef struct +{ + void *lib; + const char *libname; +} waylanddynlib; + +#ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC +#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC NULL +#endif +#ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL +#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL NULL +#endif +#ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR +#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR NULL +#endif +#ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON +#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON NULL +#endif + +static waylanddynlib waylandlibs[] = { + {NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC}, + {NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL}, + {NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR}, + {NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON} +}; + +static void * +WAYLAND_GetSym(const char *fnname, int *pHasModule) +{ + int i; + void *fn = NULL; + for (i = 0; i < SDL_TABLESIZE(waylandlibs); i++) { + if (waylandlibs[i].lib != NULL) { + fn = SDL_LoadFunction(waylandlibs[i].lib, fnname); + if (fn != NULL) + break; + } + } + +#if DEBUG_DYNAMIC_WAYLAND + if (fn != NULL) + SDL_Log("WAYLAND: Found '%s' in %s (%p)\n", fnname, waylandlibs[i].libname, fn); + else + SDL_Log("WAYLAND: Symbol '%s' NOT FOUND!\n", fnname); +#endif + + if (fn == NULL) + *pHasModule = 0; /* kill this module. */ + + return fn; +} + +#endif /* SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC */ + +/* Define all the function pointers and wrappers... */ +#define SDL_WAYLAND_MODULE(modname) int SDL_WAYLAND_HAVE_##modname = 0; +#define SDL_WAYLAND_SYM(rc,fn,params) SDL_DYNWAYLANDFN_##fn WAYLAND_##fn = NULL; +#define SDL_WAYLAND_INTERFACE(iface) const struct wl_interface *WAYLAND_##iface = NULL; +#include "SDL_waylandsym.h" +#undef SDL_WAYLAND_MODULE +#undef SDL_WAYLAND_SYM +#undef SDL_WAYLAND_INTERFACE + +static int wayland_load_refcount = 0; + +void +SDL_WAYLAND_UnloadSymbols(void) +{ + /* Don't actually unload if more than one module is using the libs... */ + if (wayland_load_refcount > 0) { + if (--wayland_load_refcount == 0) { +#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC + int i; +#endif + + /* set all the function pointers to NULL. */ +#define SDL_WAYLAND_MODULE(modname) SDL_WAYLAND_HAVE_##modname = 0; +#define SDL_WAYLAND_SYM(rc,fn,params) WAYLAND_##fn = NULL; +#define SDL_WAYLAND_INTERFACE(iface) WAYLAND_##iface = NULL; +#include "SDL_waylandsym.h" +#undef SDL_WAYLAND_MODULE +#undef SDL_WAYLAND_SYM +#undef SDL_WAYLAND_INTERFACE + + +#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC + for (i = 0; i < SDL_TABLESIZE(waylandlibs); i++) { + if (waylandlibs[i].lib != NULL) { + SDL_UnloadObject(waylandlibs[i].lib); + waylandlibs[i].lib = NULL; + } + } +#endif + } + } +} + +/* returns non-zero if all needed symbols were loaded. */ +int +SDL_WAYLAND_LoadSymbols(void) +{ + int rc = 1; /* always succeed if not using Dynamic WAYLAND stuff. */ + + /* deal with multiple modules (dga, wayland, etc) needing these symbols... */ + if (wayland_load_refcount++ == 0) { +#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC + int i; + int *thismod = NULL; + for (i = 0; i < SDL_TABLESIZE(waylandlibs); i++) { + if (waylandlibs[i].libname != NULL) { + waylandlibs[i].lib = SDL_LoadObject(waylandlibs[i].libname); + } + } + +#define SDL_WAYLAND_MODULE(modname) SDL_WAYLAND_HAVE_##modname = 1; /* default yes */ +#define SDL_WAYLAND_SYM(rc,fn,params) +#define SDL_WAYLAND_INTERFACE(iface) +#include "SDL_waylandsym.h" +#undef SDL_WAYLAND_MODULE +#undef SDL_WAYLAND_SYM +#undef SDL_WAYLAND_INTERFACE + +#define SDL_WAYLAND_MODULE(modname) thismod = &SDL_WAYLAND_HAVE_##modname; +#define SDL_WAYLAND_SYM(rc,fn,params) WAYLAND_##fn = (SDL_DYNWAYLANDFN_##fn) WAYLAND_GetSym(#fn,thismod); +#define SDL_WAYLAND_INTERFACE(iface) WAYLAND_##iface = (struct wl_interface *) WAYLAND_GetSym(#iface,thismod); +#include "SDL_waylandsym.h" +#undef SDL_WAYLAND_MODULE +#undef SDL_WAYLAND_SYM +#undef SDL_WAYLAND_INTERFACE + + if (SDL_WAYLAND_HAVE_WAYLAND_CLIENT) { + /* all required symbols loaded. */ + SDL_ClearError(); + } else { + /* in case something got loaded... */ + SDL_WAYLAND_UnloadSymbols(); + rc = 0; + } + +#else /* no dynamic WAYLAND */ + +#define SDL_WAYLAND_MODULE(modname) SDL_WAYLAND_HAVE_##modname = 1; /* default yes */ +#define SDL_WAYLAND_SYM(rc,fn,params) WAYLAND_##fn = fn; +#define SDL_WAYLAND_INTERFACE(iface) WAYLAND_##iface = &iface; +#include "SDL_waylandsym.h" +#undef SDL_WAYLAND_MODULE +#undef SDL_WAYLAND_SYM +#undef SDL_WAYLAND_INTERFACE + +#endif + } + + return rc; +} + +#endif /* SDL_VIDEO_DRIVER_WAYLAND */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/wayland/SDL_waylanddyn.h b/src/video/wayland/SDL_waylanddyn.h new file mode 100644 index 0000000000000..bf1bc924ec1c3 --- /dev/null +++ b/src/video/wayland/SDL_waylanddyn.h @@ -0,0 +1,103 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 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. +*/ + +#ifndef _SDL_waylanddyn_h +#define _SDL_waylanddyn_h + +#include "../../SDL_internal.h" + +/* We can't include wayland-client.h here + * but we need some structs from it + */ +struct wl_interface; +struct wl_proxy; +struct wl_event_queue; +struct wl_display; +struct wl_surface; +struct wl_shm; + +#include +#include "wayland-cursor.h" +#include "wayland-util.h" +#include "xkbcommon/xkbcommon.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +int SDL_WAYLAND_LoadSymbols(void); +void SDL_WAYLAND_UnloadSymbols(void); + +#define SDL_WAYLAND_MODULE(modname) extern int SDL_WAYLAND_HAVE_##modname; +#define SDL_WAYLAND_SYM(rc,fn,params) \ + typedef rc (*SDL_DYNWAYLANDFN_##fn) params; \ + extern SDL_DYNWAYLANDFN_##fn WAYLAND_##fn; +#define SDL_WAYLAND_INTERFACE(iface) extern const struct wl_interface *WAYLAND_##iface; +#include "SDL_waylandsym.h" +#undef SDL_WAYLAND_MODULE +#undef SDL_WAYLAND_SYM +#undef SDL_WAYLAND_INTERFACE + + +#ifdef __cplusplus +} +#endif + +#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC + +#ifdef _WAYLAND_CLIENT_H +#error Do not include wayland-client ahead of SDL_waylanddyn.h in dynamic loading mode +#endif + +/* wayland-client-protocol.h included from wayland-client.h + * has inline functions that require these to be defined in dynamic loading mode + */ + +#define wl_proxy_create (*WAYLAND_wl_proxy_create) +#define wl_proxy_destroy (*WAYLAND_wl_proxy_destroy) +#define wl_proxy_marshal (*WAYLAND_wl_proxy_marshal) +#define wl_proxy_set_user_data (*WAYLAND_wl_proxy_set_user_data) +#define wl_proxy_get_user_data (*WAYLAND_wl_proxy_get_user_data) +#define wl_proxy_add_listener (*WAYLAND_wl_proxy_add_listener) + +#define wl_seat_interface (*WAYLAND_wl_seat_interface) +#define wl_surface_interface (*WAYLAND_wl_surface_interface) +#define wl_shm_pool_interface (*WAYLAND_wl_shm_pool_interface) +#define wl_buffer_interface (*WAYLAND_wl_buffer_interface) +#define wl_registry_interface (*WAYLAND_wl_registry_interface) +#define wl_shell_surface_interface (*WAYLAND_wl_shell_surface_interface) +#define wl_region_interface (*WAYLAND_wl_region_interface) +#define wl_pointer_interface (*WAYLAND_wl_pointer_interface) +#define wl_keyboard_interface (*WAYLAND_wl_keyboard_interface) +#define wl_compositor_interface (*WAYLAND_wl_compositor_interface) +#define wl_output_interface (*WAYLAND_wl_output_interface) +#define wl_shell_interface (*WAYLAND_wl_shell_interface) +#define wl_shm_interface (*WAYLAND_wl_shm_interface) + +#endif /* SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC */ + +#include "wayland-client.h" +#include "wayland-egl.h" + +#endif /* !defined _SDL_waylanddyn_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c index b002a050043bd..3af798d76ea52 100644 --- a/src/video/wayland/SDL_waylandevents.c +++ b/src/video/wayland/SDL_waylandevents.c @@ -19,7 +19,7 @@ 3. This notice may not be removed or altered from any source distribution. */ -#include "SDL_config.h" +#include "../../SDL_internal.h" #include "SDL_stdinc.h" #include "SDL_assert.h" @@ -32,6 +32,8 @@ #include "SDL_waylandevents_c.h" #include "SDL_waylandwindow.h" +#include "SDL_waylanddyn.h" + #include #include #include @@ -60,14 +62,14 @@ Wayland_PumpEvents(_THIS) SDL_VideoData *d = _this->driverdata; struct pollfd pfd[1]; - pfd[0].fd = wl_display_get_fd(d->display); + pfd[0].fd = WAYLAND_wl_display_get_fd(d->display); pfd[0].events = POLLIN; poll(pfd, 1, 0); if (pfd[0].revents & POLLIN) - wl_display_dispatch(d->display); + WAYLAND_wl_display_dispatch(d->display); else - wl_display_dispatch_pending(d->display); + WAYLAND_wl_display_dispatch_pending(d->display); } static void @@ -199,7 +201,7 @@ keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard, return; } - input->xkb.keymap = xkb_map_new_from_string(input->display->xkb_context, + input->xkb.keymap = WAYLAND_xkb_keymap_new_from_string(input->display->xkb_context, map_str, XKB_KEYMAP_FORMAT_TEXT_V1, 0); @@ -211,10 +213,10 @@ keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard, return; } - input->xkb.state = xkb_state_new(input->xkb.keymap); + input->xkb.state = WAYLAND_xkb_state_new(input->xkb.keymap); if (!input->xkb.state) { fprintf(stderr, "failed to create XKB state\n"); - xkb_map_unref(input->xkb.keymap); + WAYLAND_xkb_keymap_unref(input->xkb.keymap); input->xkb.keymap = NULL; return; } @@ -266,11 +268,11 @@ keyboard_handle_key(void *data, struct wl_keyboard *keyboard, return; // TODO can this happen? - if (xkb_key_get_syms(input->xkb.state, key + 8, &syms) != 1) + if (WAYLAND_xkb_state_key_get_syms(input->xkb.state, key + 8, &syms) != 1) return; if (state) { - size = xkb_keysym_to_utf8(syms[0], text, sizeof text); + size = WAYLAND_xkb_keysym_to_utf8(syms[0], text, sizeof text); if (size > 0) { text[size] = 0; @@ -287,7 +289,7 @@ keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard, { struct SDL_WaylandInput *input = data; - xkb_state_update_mask(input->xkb.state, mods_depressed, mods_latched, + WAYLAND_xkb_state_update_mask(input->xkb.state, mods_depressed, mods_latched, mods_locked, 0, 0, group); } @@ -349,7 +351,7 @@ Wayland_display_add_input(SDL_VideoData *d, uint32_t id) wl_seat_add_listener(input->seat, &seat_listener, input); wl_seat_set_user_data(input->seat, input); - wayland_schedule_write(d); + WAYLAND_wl_display_flush(d->display); } void Wayland_display_destroy_input(SDL_VideoData *d) @@ -369,10 +371,10 @@ void Wayland_display_destroy_input(SDL_VideoData *d) wl_seat_destroy(input->seat); if (input->xkb.state) - xkb_state_unref(input->xkb.state); + WAYLAND_xkb_state_unref(input->xkb.state); if (input->xkb.keymap) - xkb_map_unref(input->xkb.keymap); + WAYLAND_xkb_keymap_unref(input->xkb.keymap); free(input); d->input = NULL; diff --git a/src/video/wayland/SDL_waylandevents_c.h b/src/video/wayland/SDL_waylandevents_c.h index ed5ff7cc80236..cc88cde9de499 100644 --- a/src/video/wayland/SDL_waylandevents_c.h +++ b/src/video/wayland/SDL_waylandevents_c.h @@ -19,7 +19,7 @@ 3. This notice may not be removed or altered from any source distribution. */ -#include "SDL_config.h" +#include "../../SDL_internal.h" #ifndef _SDL_waylandevents_h #define _SDL_waylandevents_h diff --git a/src/video/wayland/SDL_waylandmouse.c b/src/video/wayland/SDL_waylandmouse.c index 62c65e94c8b72..3609db6982a5c 100644 --- a/src/video/wayland/SDL_waylandmouse.c +++ b/src/video/wayland/SDL_waylandmouse.c @@ -31,14 +31,17 @@ #include #include +#include "../../SDL_internal.h" #include "../SDL_sysvideo.h" -#include "SDL_config.h" #include "SDL_mouse.h" #include "../../events/SDL_mouse_c.h" #include "SDL_waylandvideo.h" #include "SDL_waylandevents_c.h" +#include "SDL_waylanddyn.h" +#include "wayland-cursor.h" + #include "SDL_assert.h" #if SDL_VIDEO_DRIVER_WAYLAND @@ -210,7 +213,7 @@ CreateCursorFromWlCursor(SDL_VideoData *d, struct wl_cursor *wlcursor) data->buffer = NULL; data->surface = wl_compositor_create_surface(d->compositor); wl_surface_attach(data->surface, - wl_cursor_image_get_buffer(wlcursor->images[0]), + WAYLAND_wl_cursor_image_get_buffer(wlcursor->images[0]), 0, 0); wl_surface_damage(data->surface, @@ -236,7 +239,7 @@ Wayland_CreateDefaultCursor() SDL_VideoData *data = device->driverdata; return CreateCursorFromWlCursor (data, - wl_cursor_theme_get_cursor(data->cursor_theme, + WAYLAND_wl_cursor_theme_get_cursor(data->cursor_theme, "left_ptr")); } @@ -254,40 +257,40 @@ Wayland_CreateSystemCursor(SDL_SystemCursor id) SDL_assert(0); return NULL; case SDL_SYSTEM_CURSOR_ARROW: - cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "left_ptr"); + cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "left_ptr"); break; case SDL_SYSTEM_CURSOR_IBEAM: - cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "xterm"); + cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "xterm"); break; case SDL_SYSTEM_CURSOR_WAIT: - cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "wait"); + cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "wait"); break; case SDL_SYSTEM_CURSOR_CROSSHAIR: - cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "hand1"); + cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "hand1"); break; case SDL_SYSTEM_CURSOR_WAITARROW: - cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "wait"); + cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "wait"); break; case SDL_SYSTEM_CURSOR_SIZENWSE: - cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "hand1"); + cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "hand1"); break; case SDL_SYSTEM_CURSOR_SIZENESW: - cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "hand1"); + cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "hand1"); break; case SDL_SYSTEM_CURSOR_SIZEWE: - cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "hand1"); + cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "hand1"); break; case SDL_SYSTEM_CURSOR_SIZENS: - cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "hand1"); + cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "hand1"); break; case SDL_SYSTEM_CURSOR_SIZEALL: - cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "hand1"); + cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "hand1"); break; case SDL_SYSTEM_CURSOR_NO: - cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "xterm"); + cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "xterm"); break; case SDL_SYSTEM_CURSOR_HAND: - cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "hand1"); + cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "hand1"); break; } diff --git a/src/video/wayland/SDL_waylandmouse.h b/src/video/wayland/SDL_waylandmouse.h index f434b9d82c902..3ccd7f1ce893c 100644 --- a/src/video/wayland/SDL_waylandmouse.h +++ b/src/video/wayland/SDL_waylandmouse.h @@ -19,7 +19,7 @@ 3. This notice may not be removed or altered from any source distribution. */ -#include "SDL_config.h" +#include "../../SDL_internal.h" #include "SDL_mouse.h" #include "SDL_waylandvideo.h" diff --git a/src/video/wayland/SDL_waylandopengles.c b/src/video/wayland/SDL_waylandopengles.c index 7a1383981637f..47f0161c4b408 100644 --- a/src/video/wayland/SDL_waylandopengles.c +++ b/src/video/wayland/SDL_waylandopengles.c @@ -18,7 +18,7 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ -#include "SDL_config.h" +#include "../../SDL_internal.h" #if SDL_VIDEO_DRIVER_WAYLAND && SDL_VIDEO_OPENGL_EGL @@ -26,6 +26,7 @@ #include "SDL_waylandopengles.h" #include "SDL_waylandwindow.h" #include "SDL_waylandevents_c.h" +#include "SDL_waylanddyn.h" /* EGL implementation of SDL OpenGL ES support */ @@ -37,7 +38,7 @@ Wayland_GLES_LoadLibrary(_THIS, const char *path) { ret = SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType) data->display); Wayland_PumpEvents(_this); - wayland_schedule_write(data); + WAYLAND_wl_display_flush(data->display); return ret; } @@ -48,7 +49,7 @@ Wayland_GLES_CreateContext(_THIS, SDL_Window * window) { SDL_GLContext context; context = SDL_EGL_CreateContext(_this, ((SDL_WindowData *) window->driverdata)->egl_surface); - wayland_schedule_write(_this->driverdata); + WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display ); return context; } @@ -57,7 +58,7 @@ void Wayland_GLES_SwapWindow(_THIS, SDL_Window *window) { SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface); - wayland_schedule_write(_this->driverdata); + WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display ); } @@ -73,7 +74,7 @@ Wayland_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) ret = SDL_EGL_MakeCurrent(_this, NULL, NULL); } - wayland_schedule_write(_this->driverdata); + WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display ); return ret; } @@ -82,7 +83,7 @@ void Wayland_GLES_DeleteContext(_THIS, SDL_GLContext context) { SDL_EGL_DeleteContext(_this, context); - wayland_schedule_write(_this->driverdata); + WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display ); } #endif /* SDL_VIDEO_DRIVER_WAYLAND && SDL_VIDEO_OPENGL_EGL */ diff --git a/src/video/wayland/SDL_waylandopengles.h b/src/video/wayland/SDL_waylandopengles.h index 2deed0c14bb2e..084a4bdd677d7 100644 --- a/src/video/wayland/SDL_waylandopengles.h +++ b/src/video/wayland/SDL_waylandopengles.h @@ -18,7 +18,7 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ -#include "SDL_config.h" +#include "../../SDL_internal.h" #ifndef _SDL_waylandopengles_h #define _SDL_waylandopengles_h diff --git a/src/video/wayland/SDL_waylandsym.h b/src/video/wayland/SDL_waylandsym.h new file mode 100644 index 0000000000000..1494d3f48e137 --- /dev/null +++ b/src/video/wayland/SDL_waylandsym.h @@ -0,0 +1,102 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 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* */ + +SDL_WAYLAND_MODULE(WAYLAND_CLIENT) +SDL_WAYLAND_SYM(void, wl_proxy_marshal, (struct wl_proxy *, uint32_t, ...)) +SDL_WAYLAND_SYM(struct wl_proxy *, wl_proxy_create, (struct wl_proxy *, const struct wl_interface *)) +SDL_WAYLAND_SYM(void, wl_proxy_destroy, (struct wl_proxy *)) +SDL_WAYLAND_SYM(int, wl_proxy_add_listener, (struct wl_proxy *, void (**)(void), void *)) +SDL_WAYLAND_SYM(void, wl_proxy_set_user_data, (struct wl_proxy *, void *)) +SDL_WAYLAND_SYM(void *, wl_proxy_get_user_data, (struct wl_proxy *)) +SDL_WAYLAND_SYM(uint32_t, wl_proxy_get_id, (struct wl_proxy *)) +SDL_WAYLAND_SYM(const char *, wl_proxy_get_class, (struct wl_proxy *)) +SDL_WAYLAND_SYM(void, wl_proxy_set_queue, (struct wl_proxy *, struct wl_event_queue *)) +SDL_WAYLAND_SYM(struct wl_display *, wl_display_connect, (const char *)) +SDL_WAYLAND_SYM(struct wl_display *, wl_display_connect_to_fd, (int)) +SDL_WAYLAND_SYM(void, wl_display_disconnect, (struct wl_display *)) +SDL_WAYLAND_SYM(int, wl_display_get_fd, (struct wl_display *)) +SDL_WAYLAND_SYM(int, wl_display_dispatch, (struct wl_display *)) +SDL_WAYLAND_SYM(int, wl_display_dispatch_queue, (struct wl_display *, struct wl_event_queue *)) +SDL_WAYLAND_SYM(int, wl_display_dispatch_queue_pending, (struct wl_display *, struct wl_event_queue *)) +SDL_WAYLAND_SYM(int, wl_display_dispatch_pending, (struct wl_display *)) +SDL_WAYLAND_SYM(int, wl_display_get_error, (struct wl_display *)) +SDL_WAYLAND_SYM(int, wl_display_flush, (struct wl_display *)) +SDL_WAYLAND_SYM(int, wl_display_roundtrip, (struct wl_display *)) +SDL_WAYLAND_SYM(struct wl_event_queue *, wl_display_create_queue, (struct wl_display *)) +SDL_WAYLAND_SYM(void, wl_log_set_handler_client, (wl_log_func_t)) +SDL_WAYLAND_SYM(void, wl_list_init, (struct wl_list *)) +SDL_WAYLAND_SYM(void, wl_list_insert, (struct wl_list *, struct wl_list *) ) +SDL_WAYLAND_SYM(void, wl_list_remove, (struct wl_list *)) +SDL_WAYLAND_SYM(int, wl_list_length, (const struct wl_list *)) +SDL_WAYLAND_SYM(int, wl_list_empty, (const struct wl_list *)) +SDL_WAYLAND_SYM(void, wl_list_insert_list, (struct wl_list *, struct wl_list *)) + +SDL_WAYLAND_INTERFACE(wl_seat_interface) +SDL_WAYLAND_INTERFACE(wl_surface_interface) +SDL_WAYLAND_INTERFACE(wl_shm_pool_interface) +SDL_WAYLAND_INTERFACE(wl_buffer_interface) +SDL_WAYLAND_INTERFACE(wl_registry_interface) +SDL_WAYLAND_INTERFACE(wl_shell_surface_interface) +SDL_WAYLAND_INTERFACE(wl_region_interface) +SDL_WAYLAND_INTERFACE(wl_pointer_interface) +SDL_WAYLAND_INTERFACE(wl_keyboard_interface) +SDL_WAYLAND_INTERFACE(wl_compositor_interface) +SDL_WAYLAND_INTERFACE(wl_output_interface) +SDL_WAYLAND_INTERFACE(wl_shell_interface) +SDL_WAYLAND_INTERFACE(wl_shm_interface) + +SDL_WAYLAND_MODULE(WAYLAND_EGL) +SDL_WAYLAND_SYM(struct wl_egl_window *, wl_egl_window_create, (struct wl_surface *, int, int)) +SDL_WAYLAND_SYM(void, wl_egl_window_destroy, (struct wl_egl_window *)) +SDL_WAYLAND_SYM(void, wl_egl_window_resize, (struct wl_egl_window *, int, int, int, int)) +SDL_WAYLAND_SYM(void, wl_egl_window_get_attached_size, (struct wl_egl_window *, int *, int *)) + +SDL_WAYLAND_MODULE(WAYLAND_CURSOR) +SDL_WAYLAND_SYM(struct wl_cursor_theme *, wl_cursor_theme_load, (const char *, int , struct wl_shm *)) +SDL_WAYLAND_SYM(void, wl_cursor_theme_destroy, (struct wl_cursor_theme *)) +SDL_WAYLAND_SYM(struct wl_cursor *, wl_cursor_theme_get_cursor, (struct wl_cursor_theme *, const char *)) +SDL_WAYLAND_SYM(struct wl_buffer *, wl_cursor_image_get_buffer, (struct wl_cursor_image *)) +SDL_WAYLAND_SYM(int, wl_cursor_frame, (struct wl_cursor *, uint32_t)) + +SDL_WAYLAND_MODULE(WAYLAND_XKB) +SDL_WAYLAND_SYM(int, xkb_state_key_get_syms, (struct xkb_state *, xkb_keycode_t, const xkb_keysym_t **)) +SDL_WAYLAND_SYM(int, xkb_keysym_to_utf8, (xkb_keysym_t, char *, size_t) ) +SDL_WAYLAND_SYM(struct xkb_keymap *, xkb_keymap_new_from_string, (struct xkb_context *, const char *, enum xkb_keymap_format, enum xkb_keymap_compile_flags)) +SDL_WAYLAND_SYM(struct xkb_state *, xkb_state_new, (struct xkb_keymap *) ) +SDL_WAYLAND_SYM(void, xkb_keymap_unref, (struct xkb_keymap *) ) +SDL_WAYLAND_SYM(void, xkb_state_unref, (struct xkb_state *) ) +SDL_WAYLAND_SYM(void, xkb_context_unref, (struct xkb_context *) ) +SDL_WAYLAND_SYM(struct xkb_context *, xkb_context_new, (enum xkb_context_flags flags) ) +SDL_WAYLAND_SYM(enum xkb_state_component, xkb_state_update_mask, (struct xkb_state *state,\ + xkb_mod_mask_t depressed_mods,\ + xkb_mod_mask_t latched_mods,\ + xkb_mod_mask_t locked_mods,\ + xkb_layout_index_t depressed_layout,\ + xkb_layout_index_t latched_layout,\ + xkb_layout_index_t locked_layout) ) + + +/* *INDENT-ON* */ + +/* vi: set ts=4 sw=4 expandtab: */ +//SDL_WAYLAND_SYM(ret, fn, params) \ No newline at end of file diff --git a/src/video/wayland/SDL_waylandtouch.c b/src/video/wayland/SDL_waylandtouch.c index 9edf2e7ed539a..2c55d6d9ff062 100644 --- a/src/video/wayland/SDL_waylandtouch.c +++ b/src/video/wayland/SDL_waylandtouch.c @@ -21,7 +21,7 @@ /* Contributed by Thomas Perl */ -#include "SDL_config.h" +#include "../../SDL_internal.h" #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH @@ -118,6 +118,7 @@ touch_handle_configure(void *data, { } + /* wayland-qt-touch-extension.c BEGINS */ static const struct qt_touch_extension_listener touch_listener = { @@ -183,13 +184,23 @@ WL_EXPORT const struct wl_interface qt_windowmanager_interface = { /* wayland-qt-surface-extension.c BEGINS */ extern const struct wl_interface qt_extended_surface_interface; +#ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC extern const struct wl_interface wl_surface_interface; +#endif static const struct wl_interface *qt_surface_extension_types[] = { NULL, NULL, &qt_extended_surface_interface, +#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC + /* FIXME: Set this dynamically to (*WAYLAND_wl_surface_interface) ? + * The value comes from auto generated code and does + * not appear to actually be used anywhere + */ + NULL, +#else &wl_surface_interface, +#endif }; static const struct wl_message qt_surface_extension_requests[] = { diff --git a/src/video/wayland/SDL_waylandtouch.h b/src/video/wayland/SDL_waylandtouch.h index ccb645bd9f280..fe5149922e076 100644 --- a/src/video/wayland/SDL_waylandtouch.h +++ b/src/video/wayland/SDL_waylandtouch.h @@ -19,7 +19,7 @@ 3. This notice may not be removed or altered from any source distribution. */ -#include "SDL_config.h" +#include "../../SDL_internal.h" #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH @@ -29,8 +29,9 @@ #include "SDL_waylandvideo.h" #include #include -#include "wayland-client.h" #include "wayland-util.h" +#include "SDL_waylanddyn.h" + void Wayland_touch_create(SDL_VideoData *data, uint32_t id); void Wayland_touch_destroy(SDL_VideoData *data); @@ -89,7 +90,7 @@ qt_surface_extension_get_user_data(struct qt_surface_extension *qt_surface_exten static inline void qt_surface_extension_destroy(struct qt_surface_extension *qt_surface_extension) { - wl_proxy_destroy((struct wl_proxy *) qt_surface_extension); + WAYLAND_wl_proxy_destroy((struct wl_proxy *) qt_surface_extension); } static inline struct qt_extended_surface * @@ -102,7 +103,7 @@ qt_surface_extension_get_extended_surface(struct qt_surface_extension *qt_surfac if (!id) return NULL; - wl_proxy_marshal((struct wl_proxy *) qt_surface_extension, + WAYLAND_wl_proxy_marshal((struct wl_proxy *) qt_surface_extension, QT_SURFACE_EXTENSION_GET_EXTENDED_SURFACE, id, surface); return (struct qt_extended_surface *) id; @@ -166,39 +167,39 @@ qt_extended_surface_add_listener(struct qt_extended_surface *qt_extended_surface static inline void qt_extended_surface_set_user_data(struct qt_extended_surface *qt_extended_surface, void *user_data) { - wl_proxy_set_user_data((struct wl_proxy *) qt_extended_surface, user_data); + WAYLAND_wl_proxy_set_user_data((struct wl_proxy *) qt_extended_surface, user_data); } static inline void * qt_extended_surface_get_user_data(struct qt_extended_surface *qt_extended_surface) { - return wl_proxy_get_user_data((struct wl_proxy *) qt_extended_surface); + return WAYLAND_wl_proxy_get_user_data((struct wl_proxy *) qt_extended_surface); } static inline void qt_extended_surface_destroy(struct qt_extended_surface *qt_extended_surface) { - wl_proxy_destroy((struct wl_proxy *) qt_extended_surface); + WAYLAND_wl_proxy_destroy((struct wl_proxy *) qt_extended_surface); } static inline void qt_extended_surface_update_generic_property(struct qt_extended_surface *qt_extended_surface, const char *name, struct wl_array *value) { - wl_proxy_marshal((struct wl_proxy *) qt_extended_surface, + WAYLAND_wl_proxy_marshal((struct wl_proxy *) qt_extended_surface, QT_EXTENDED_SURFACE_UPDATE_GENERIC_PROPERTY, name, value); } static inline void qt_extended_surface_set_content_orientation(struct qt_extended_surface *qt_extended_surface, int32_t orientation) { - wl_proxy_marshal((struct wl_proxy *) qt_extended_surface, + WAYLAND_wl_proxy_marshal((struct wl_proxy *) qt_extended_surface, QT_EXTENDED_SURFACE_SET_CONTENT_ORIENTATION, orientation); } static inline void qt_extended_surface_set_window_flags(struct qt_extended_surface *qt_extended_surface, int32_t flags) { - wl_proxy_marshal((struct wl_proxy *) qt_extended_surface, + WAYLAND_wl_proxy_marshal((struct wl_proxy *) qt_extended_surface, QT_EXTENDED_SURFACE_SET_WINDOW_FLAGS, flags); } @@ -269,25 +270,25 @@ qt_touch_extension_add_listener(struct qt_touch_extension *qt_touch_extension, static inline void qt_touch_extension_set_user_data(struct qt_touch_extension *qt_touch_extension, void *user_data) { - wl_proxy_set_user_data((struct wl_proxy *) qt_touch_extension, user_data); + WAYLAND_wl_proxy_set_user_data((struct wl_proxy *) qt_touch_extension, user_data); } static inline void * qt_touch_extension_get_user_data(struct qt_touch_extension *qt_touch_extension) { - return wl_proxy_get_user_data((struct wl_proxy *) qt_touch_extension); + return WAYLAND_wl_proxy_get_user_data((struct wl_proxy *) qt_touch_extension); } static inline void qt_touch_extension_destroy(struct qt_touch_extension *qt_touch_extension) { - wl_proxy_destroy((struct wl_proxy *) qt_touch_extension); + WAYLAND_wl_proxy_destroy((struct wl_proxy *) qt_touch_extension); } static inline void qt_touch_extension_dummy(struct qt_touch_extension *qt_touch_extension) { - wl_proxy_marshal((struct wl_proxy *) qt_touch_extension, + WAYLAND_wl_proxy_marshal((struct wl_proxy *) qt_touch_extension, QT_TOUCH_EXTENSION_DUMMY); } @@ -324,25 +325,25 @@ qt_windowmanager_add_listener(struct qt_windowmanager *qt_windowmanager, static inline void qt_windowmanager_set_user_data(struct qt_windowmanager *qt_windowmanager, void *user_data) { - wl_proxy_set_user_data((struct wl_proxy *) qt_windowmanager, user_data); + WAYLAND_wl_proxy_set_user_data((struct wl_proxy *) qt_windowmanager, user_data); } static inline void * qt_windowmanager_get_user_data(struct qt_windowmanager *qt_windowmanager) { - return wl_proxy_get_user_data((struct wl_proxy *) qt_windowmanager); + return WAYLAND_wl_proxy_get_user_data((struct wl_proxy *) qt_windowmanager); } static inline void qt_windowmanager_destroy(struct qt_windowmanager *qt_windowmanager) { - wl_proxy_destroy((struct wl_proxy *) qt_windowmanager); + WAYLAND_wl_proxy_destroy((struct wl_proxy *) qt_windowmanager); } static inline void qt_windowmanager_open_url(struct qt_windowmanager *qt_windowmanager, uint32_t remaining, const char *url) { - wl_proxy_marshal((struct wl_proxy *) qt_windowmanager, + WAYLAND_wl_proxy_marshal((struct wl_proxy *) qt_windowmanager, QT_WINDOWMANAGER_OPEN_URL, remaining, url); } diff --git a/src/video/wayland/SDL_waylandvideo.c b/src/video/wayland/SDL_waylandvideo.c index 5c845ac450032..b8db46981f9d2 100644 --- a/src/video/wayland/SDL_waylandvideo.c +++ b/src/video/wayland/SDL_waylandvideo.c @@ -19,10 +19,11 @@ 3. This notice may not be removed or altered from any source distribution. */ -#include "SDL_config.h" +#include "../../SDL_internal.h" #include "SDL_video.h" #include "SDL_mouse.h" +#include "SDL_stdinc.h" #include "../../events/SDL_events_c.h" #include "SDL_waylandvideo.h" @@ -35,6 +36,9 @@ #include #include +#include "SDL_waylanddyn.h" +#include + #define WAYLANDVID_DRIVER_NAME "wayland" struct wayland_mode { @@ -59,10 +63,12 @@ static int Wayland_Available(void) { struct wl_display *display = NULL; - - display = wl_display_connect(NULL); - if (display != NULL) { - wl_display_disconnect(display); + if (SDL_WAYLAND_LoadSymbols()) { + display = WAYLAND_wl_display_connect(NULL); + if (display != NULL) { + WAYLAND_wl_display_disconnect(display); + } + SDL_WAYLAND_UnloadSymbols(); } return (display != NULL); @@ -72,12 +78,17 @@ static void Wayland_DeleteDevice(SDL_VideoDevice *device) { SDL_free(device); + SDL_WAYLAND_UnloadSymbols(); } static SDL_VideoDevice * Wayland_CreateDevice(int devindex) { SDL_VideoDevice *device; + + if (!SDL_WAYLAND_LoadSymbols()) { + return NULL; + } /* Initialize all variables that we clean on shutdown */ device = SDL_calloc(1, sizeof(SDL_VideoDevice)); @@ -133,13 +144,13 @@ wayland_add_mode(SDL_VideoData *d, SDL_DisplayMode m) return; /* Add new mode to the list */ - mode = SDL_calloc(1, sizeof *mode); + mode = (struct wayland_mode *) SDL_calloc(1, sizeof *mode); if (!mode) return; mode->mode = m; - wl_list_insert(&d->modes_list, &mode->link); + WAYLAND_wl_list_insert(&d->modes_list, &mode->link); } static void @@ -227,7 +238,7 @@ display_handle_global(void *data, struct wl_registry *registry, uint32_t id, const char *interface, uint32_t version) { SDL_VideoData *d = data; - + if (strcmp(interface, "wl_compositor") == 0) { d->compositor = wl_registry_bind(d->registry, id, &wl_compositor_interface, 1); } else if (strcmp(interface, "wl_output") == 0) { @@ -239,8 +250,8 @@ display_handle_global(void *data, struct wl_registry *registry, uint32_t id, d->shell = wl_registry_bind(d->registry, id, &wl_shell_interface, 1); } else if (strcmp(interface, "wl_shm") == 0) { d->shm = wl_registry_bind(registry, id, &wl_shm_interface, 1); - d->cursor_theme = wl_cursor_theme_load(NULL, 32, d->shm); - d->default_cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "left_ptr"); + d->cursor_theme = WAYLAND_wl_cursor_theme_load(NULL, 32, d->shm); + d->default_cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "left_ptr"); wl_shm_add_listener(d->shm, &shm_listener, d); #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH @@ -265,7 +276,10 @@ int Wayland_VideoInit(_THIS) { SDL_VideoData *data; - + SDL_VideoDisplay display; + SDL_DisplayMode mode; + int i; + data = malloc(sizeof *data); if (data == NULL) return 0; @@ -273,29 +287,41 @@ Wayland_VideoInit(_THIS) _this->driverdata = data; - wl_list_init(&data->modes_list); + WAYLAND_wl_list_init(&data->modes_list); - data->display = wl_display_connect(NULL); + data->display = WAYLAND_wl_display_connect(NULL); if (data->display == NULL) { SDL_SetError("Failed to connect to a Wayland display"); return 0; } data->registry = wl_display_get_registry(data->display); + + if ( data->registry == NULL) { + SDL_SetError("Failed to get the Wayland registry"); + return 0; + } + wl_registry_add_listener(data->registry, ®istry_listener, data); - while (data->screen_allocation.width == 0) - wl_display_dispatch(data->display); + for (i=0; i < 100; i++) { + if (data->screen_allocation.width != 0 || WAYLAND_wl_display_get_error(data->display) != 0) { + break; + } + WAYLAND_wl_display_dispatch(data->display); + } + + if (data->screen_allocation.width == 0) { + SDL_SetError("Failed while waiting for screen allocation: %d ", WAYLAND_wl_display_get_error(data->display)); + return 0; + } - data->xkb_context = xkb_context_new(0); + data->xkb_context = WAYLAND_xkb_context_new(0); if (!data->xkb_context) { SDL_SetError("Failed to create XKB context"); return 0; } - SDL_VideoDisplay display; - SDL_DisplayMode mode; - /* Use a fake 32-bpp desktop mode */ mode.format = SDL_PIXELFORMAT_RGB888; mode.w = data->screen_allocation.width; @@ -311,7 +337,7 @@ Wayland_VideoInit(_THIS) Wayland_InitMouse (); - wayland_schedule_write(data); + WAYLAND_wl_display_flush(data->display); return 0; } @@ -363,7 +389,7 @@ Wayland_VideoQuit(_THIS) Wayland_display_destroy_input(data); if (data->xkb_context) { - xkb_context_unref(data->xkb_context); + WAYLAND_xkb_context_unref(data->xkb_context); data->xkb_context = NULL; } #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH @@ -380,7 +406,7 @@ Wayland_VideoQuit(_THIS) wl_shm_destroy(data->shm); if (data->cursor_theme) - wl_cursor_theme_destroy(data->cursor_theme); + WAYLAND_wl_cursor_theme_destroy(data->cursor_theme); if (data->shell) wl_shell_destroy(data->shell); @@ -389,12 +415,12 @@ Wayland_VideoQuit(_THIS) wl_compositor_destroy(data->compositor); if (data->display) { - wl_display_flush(data->display); - wl_display_disconnect(data->display); + WAYLAND_wl_display_flush(data->display); + WAYLAND_wl_display_disconnect(data->display); } wl_list_for_each_safe(m, t, &data->modes_list, link) { - wl_list_remove(&m->link); + WAYLAND_wl_list_remove(&m->link); free(m); } diff --git a/src/video/wayland/SDL_waylandvideo.h b/src/video/wayland/SDL_waylandvideo.h index c44a26418805b..71f93044d59b4 100644 --- a/src/video/wayland/SDL_waylandvideo.h +++ b/src/video/wayland/SDL_waylandvideo.h @@ -19,16 +19,13 @@ 3. This notice may not be removed or altered from any source distribution. */ -#include "SDL_config.h" +#include "../../SDL_internal.h" #ifndef _SDL_waylandvideo_h #define _SDL_waylandvideo_h -#include -#include -#include - #include +#include "wayland-util.h" struct xkb_context; struct SDL_WaylandInput; @@ -72,12 +69,6 @@ typedef struct { uint32_t shm_formats; } SDL_VideoData; -static inline void -wayland_schedule_write(SDL_VideoData *data) -{ - wl_display_flush(data->display); -} - #endif /* _SDL_nullvideo_h */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c index f864520cf71e8..090c494f0416b 100644 --- a/src/video/wayland/SDL_waylandwindow.c +++ b/src/video/wayland/SDL_waylandwindow.c @@ -19,7 +19,7 @@ 3. This notice may not be removed or altered from any source distribution. */ -#include "SDL_config.h" +#include "../../SDL_internal.h" #include "../SDL_sysvideo.h" #include "../../events/SDL_windowevents_c.h" @@ -104,7 +104,7 @@ void Wayland_ShowWindow(_THIS, SDL_Window *window) else wl_shell_surface_set_toplevel(wind->shell_surface); - wayland_schedule_write(_this->driverdata); + WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display ); } void @@ -120,7 +120,7 @@ Wayland_SetWindowFullscreen(_THIS, SDL_Window * window, else wl_shell_surface_set_toplevel(wind->shell_surface); - wayland_schedule_write(_this->driverdata); + WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display ); } int Wayland_CreateWindow(_THIS, SDL_Window *window) @@ -162,7 +162,7 @@ int Wayland_CreateWindow(_THIS, SDL_Window *window) c->surface_extension, data->surface); } #endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */ - data->egl_window = wl_egl_window_create(data->surface, + data->egl_window = WAYLAND_wl_egl_window_create(data->surface, window->w, window->h); /* Create the GLES window surface */ @@ -192,7 +192,7 @@ int Wayland_CreateWindow(_THIS, SDL_Window *window) wl_surface_set_opaque_region(data->surface, region); wl_region_destroy(region); - wayland_schedule_write(c); + WAYLAND_wl_display_flush(c->display); return 0; } @@ -203,9 +203,9 @@ void Wayland_SetWindowSize(_THIS, SDL_Window * window) SDL_WindowData *wind = window->driverdata; struct wl_region *region; - wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0); + WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0); - region = wl_compositor_create_region(data->compositor); + region =wl_compositor_create_region(data->compositor); wl_region_add(region, 0, 0, window->w, window->h); wl_surface_set_opaque_region(wind->surface, region); wl_region_destroy(region); @@ -220,7 +220,7 @@ void Wayland_DestroyWindow(_THIS, SDL_Window *window) if (data) { SDL_EGL_DestroySurface(_this, wind->egl_surface); - wl_egl_window_destroy(wind->egl_window); + WAYLAND_wl_egl_window_destroy(wind->egl_window); if (wind->shell_surface) wl_shell_surface_destroy(wind->shell_surface); @@ -232,7 +232,7 @@ void Wayland_DestroyWindow(_THIS, SDL_Window *window) wl_surface_destroy(wind->surface); SDL_free(wind); - wayland_schedule_write(data); + WAYLAND_wl_display_flush(data->display); } } diff --git a/src/video/wayland/SDL_waylandwindow.h b/src/video/wayland/SDL_waylandwindow.h index f65dc8fefbae9..789c43d39a2f3 100644 --- a/src/video/wayland/SDL_waylandwindow.h +++ b/src/video/wayland/SDL_waylandwindow.h @@ -19,7 +19,7 @@ 3. This notice may not be removed or altered from any source distribution. */ -#include "SDL_config.h" +#include "../../SDL_internal.h" #ifndef _SDL_waylandwindow_h #define _SDL_waylandwindow_h