From 0f7c67daabf6bbca35ec7cdad5eeeaf0988aced4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Higor=20Eur=C3=ADpedes?= Date: Fri, 15 Aug 2014 19:21:16 -0300 Subject: [PATCH 1/8] (SDL) Fix #ifdef typo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Higor Eurípedes --- input/sdl_joypad.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/input/sdl_joypad.c b/input/sdl_joypad.c index 3d8e909aa1..203fdd1a5a 100644 --- a/input/sdl_joypad.c +++ b/input/sdl_joypad.c @@ -129,7 +129,7 @@ static bool sdl_joypad_init(void) else if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0) return false; -#if HAS_SDL2 +#if HAVE_SDL2 // TODO: Add SDL_GameController support. //if (SDL_Init(SDL_INIT_GAMECONTROLLER) < 0) // RARCH_LOG("[SDL]: Failed to initialize game controller interface: %s\n", From e88f3b43553d26c1523a9fa22b9710cd615aefdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Higor=20Eur=C3=ADpedes?= Date: Fri, 15 Aug 2014 19:25:27 -0300 Subject: [PATCH 2/8] (SDL) Fix double initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Higor Eurípedes --- audio/sdl_audio.c | 7 +++++-- gfx/sdl2_gfx.c | 7 +++++-- input/sdl_joypad.c | 7 +++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/audio/sdl_audio.c b/audio/sdl_audio.c index e1bd5ab5ee..db9107e99f 100644 --- a/audio/sdl_audio.c +++ b/audio/sdl_audio.c @@ -60,8 +60,11 @@ static inline int find_num_frames(int rate, int latency) static void *sdl_audio_init(const char *device, unsigned rate, unsigned latency) { (void)device; - if (SDL_WasInit(0) == 0 && SDL_Init(SDL_INIT_AUDIO) < 0) - return NULL; + if (SDL_WasInit(0) == 0) + { + if (SDL_Init(SDL_INIT_AUDIO) < 0) + return NULL; + } else if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) return NULL; diff --git a/gfx/sdl2_gfx.c b/gfx/sdl2_gfx.c index a292a90407..215e86da47 100644 --- a/gfx/sdl2_gfx.c +++ b/gfx/sdl2_gfx.c @@ -369,8 +369,11 @@ static void *sdl2_gfx_init(const video_info_t *video, const input_driver_t **inp int i; - if (SDL_WasInit(0) == 0 && SDL_Init(SDL_INIT_VIDEO) < 0) - return NULL; + if (SDL_WasInit(0) == 0) + { + if (SDL_Init(SDL_INIT_VIDEO) < 0) + return NULL; + } else if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) return NULL; diff --git a/input/sdl_joypad.c b/input/sdl_joypad.c index 203fdd1a5a..2aee0b569a 100644 --- a/input/sdl_joypad.c +++ b/input/sdl_joypad.c @@ -124,8 +124,11 @@ static void sdl_joypad_destroy(void) static bool sdl_joypad_init(void) { unsigned i; - if (SDL_WasInit(0) == 0 && SDL_Init(SDL_INIT_JOYSTICK) < 0) - return false; + if (SDL_WasInit(0) == 0) + { + if (SDL_Init(SDL_INIT_JOYSTICK) < 0) + return false; + } else if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0) return false; From 110cde65c5c7689ac364aceb7f31400600877a88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Higor=20Eur=C3=ADpedes?= Date: Fri, 15 Aug 2014 20:20:30 -0300 Subject: [PATCH 3/8] (scaler.c) Add missing RGBA4444 to ARGB8888 conversion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Higor Eurípedes --- gfx/scaler/scaler.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gfx/scaler/scaler.c b/gfx/scaler/scaler.c index 551f64d16b..abcfc5da13 100644 --- a/gfx/scaler/scaler.c +++ b/gfx/scaler/scaler.c @@ -89,6 +89,8 @@ static bool set_direct_pix_conv(struct scaler_ctx *ctx) ctx->direct_pixconv = conv_argb8888_abgr8888; else if (ctx->in_fmt == SCALER_FMT_YUYV && ctx->out_fmt == SCALER_FMT_ARGB8888) ctx->direct_pixconv = conv_yuyv_argb8888; + else if (ctx->in_fmt == SCALER_FMT_RGBA4444 && ctx->out_fmt == SCALER_FMT_ARGB8888) + ctx->direct_pixconv = conv_rgba4444_argb8888; else return false; From 8b569a789c20e926c2c8c3c356d04a0785f77cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Higor=20Eur=C3=ADpedes?= Date: Fri, 15 Aug 2014 20:22:29 -0300 Subject: [PATCH 4/8] (SDL2) Use SDL_INIT_GAMECONTROLLER MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Higor Eurípedes --- input/sdl_joypad.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/input/sdl_joypad.c b/input/sdl_joypad.c index 2aee0b569a..eca394db74 100644 --- a/input/sdl_joypad.c +++ b/input/sdl_joypad.c @@ -32,6 +32,12 @@ typedef struct _sdl_joypad #endif } sdl_joypad_t; +#ifdef HAVE_SDL2 +const int g_subsystem = SDL_INIT_GAMECONTROLLER; +#else +const int g_subsystem = SDL_INIT_JOYSTICK; +#endif + static sdl_joypad_t g_pads[MAX_PLAYERS]; #ifdef HAVE_SDL2 static bool g_has_haptic; @@ -117,27 +123,23 @@ static void sdl_joypad_destroy(void) for (i = 0; i < MAX_PLAYERS; i++) sdl_joypad_disconnect(i); - SDL_QuitSubSystem(SDL_INIT_JOYSTICK); + SDL_QuitSubSystem(g_subsystem); memset(g_pads, 0, sizeof(g_pads)); } static bool sdl_joypad_init(void) { unsigned i; + if (SDL_WasInit(0) == 0) { - if (SDL_Init(SDL_INIT_JOYSTICK) < 0) + if (SDL_Init(g_subsystem) < 0) return false; } - else if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0) + else if (SDL_InitSubSystem(g_subsystem) < 0) return false; #if HAVE_SDL2 - // TODO: Add SDL_GameController support. - //if (SDL_Init(SDL_INIT_GAMECONTROLLER) < 0) - // RARCH_LOG("[SDL]: Failed to initialize game controller interface: %s\n", - // SDL_GetError()); - g_has_haptic = false; if (SDL_InitSubSystem(SDL_INIT_HAPTIC) < 0) RARCH_WARN("[SDL]: Failed to initialize haptic device support: %s\n", From 12d0bdfc8a481845671ac27951edf11d12f836aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Higor=20Eur=C3=ADpedes?= Date: Fri, 15 Aug 2014 21:22:54 -0300 Subject: [PATCH 5/8] (SDL2) Add SDL Game Controller (xinput and friends) support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Higor Eurípedes --- input/sdl_joypad.c | 127 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 98 insertions(+), 29 deletions(-) diff --git a/input/sdl_joypad.c b/input/sdl_joypad.c index eca394db74..8dde5f8056 100644 --- a/input/sdl_joypad.c +++ b/input/sdl_joypad.c @@ -21,6 +21,7 @@ typedef struct _sdl_joypad { SDL_Joystick *joypad; #ifdef HAVE_SDL2 + SDL_GameController *controller; SDL_Haptic *haptic; int rumble_effect; // -1 = not initialized, -2 = error/unsupported #endif @@ -43,25 +44,89 @@ static sdl_joypad_t g_pads[MAX_PLAYERS]; static bool g_has_haptic; #endif -static void sdl_joypad_connect(int id) +static const char* pad_name(unsigned id) +{ +#ifdef HAVE_SDL2 + if (g_pads[id].controller) + return SDL_GameControllerNameForIndex(id); + else + return SDL_JoystickNameForIndex(id); +#else + return SDL_JoystickName(id); +#endif +} + +static uint8_t pad_get_button(sdl_joypad_t *pad, unsigned button) +{ +#ifdef HAVE_SDL2 + /* TODO: see if a LUT like winxinput_joypad.c's button_index_to_bitmap_code is needed. */ + if (pad->controller) + return SDL_GameControllerGetButton(pad->controller, button); + else +#endif + return SDL_JoystickGetButton(pad->joypad, button); +} + +static uint8_t pad_get_hat(sdl_joypad_t *pad, unsigned hat) +{ +#ifdef HAVE_SDL2 + if (pad->controller) + return pad_get_button(pad, hat); + else +#endif + return SDL_JoystickGetHat(pad->joypad, hat); +} + +static int16_t pad_get_axis(sdl_joypad_t *pad, unsigned axis) +{ +#ifdef HAVE_SDL2 + /* TODO: see if a rarch <-> sdl translation is needed. */ + if (pad->controller) + return SDL_GameControllerGetAxis(pad->controller, axis); + else +#endif + return SDL_JoystickGetAxis(pad->joypad, axis); +} + +static void pad_connect(unsigned id) { sdl_joypad_t *pad = &g_pads[id]; - pad->joypad = SDL_JoystickOpen(id); - if (!pad->joypad) + bool success = false; + +#ifdef HAVE_SDL2 + if (SDL_IsGameController(id)) { - RARCH_ERR("[SDL]: Couldn't open SDL joystick #%u.\n", id); + pad->controller = SDL_GameControllerOpen(id); + pad->joypad = SDL_GameControllerGetJoystick(pad->controller); + + success = pad->joypad != NULL && pad->controller != NULL; + } + else +#endif + { + pad->joypad = SDL_JoystickOpen(id); + success = pad->joypad != NULL; + } + + if (!success) + { + RARCH_ERR("[SDL]: Couldn't open joystick #%u: %s.\n", id, SDL_GetError()); + + if (pad->joypad) + SDL_JoystickClose(pad->joypad); + + pad->joypad = NULL; + return; } - RARCH_LOG("[SDL]: Joypad #%u connected: %s.\n", -#ifdef HAVE_SDL2 - id, SDL_JoystickName(pad->joypad)); -#else - id, SDL_JoystickName(id)); -#endif - + RARCH_LOG("[SDL]: Joypad #%u connected: %s.\n", id, pad_name(id)); #ifdef HAVE_SDL2 + + if (pad->controller) + RARCH_LOG("[SDL]: Joypad #%u supports game controller api.\n", id); + pad->haptic = g_has_haptic ? SDL_HapticOpenFromJoystick(pad->joypad) : NULL; if (g_has_haptic && !pad->haptic) @@ -101,13 +166,19 @@ static void sdl_joypad_connect(int id) #endif } -static void sdl_joypad_disconnect(int id) +static void pad_disconnect(unsigned id) { #ifdef HAVE_SDL2 if (g_pads[id].haptic) SDL_HapticClose(g_pads[id].haptic); -#endif + if (g_pads[id].controller) + { + SDL_GameControllerClose(g_pads[id].controller); + RARCH_LOG("[SDL]: Joypad #%u disconnected.\n", id); + } + else +#endif if (g_pads[id].joypad) { SDL_JoystickClose(g_pads[id].joypad); @@ -121,7 +192,7 @@ static void sdl_joypad_destroy(void) { unsigned i; for (i = 0; i < MAX_PLAYERS; i++) - sdl_joypad_disconnect(i); + pad_disconnect(i); SDL_QuitSubSystem(g_subsystem); memset(g_pads, 0, sizeof(g_pads)); @@ -148,12 +219,14 @@ static bool sdl_joypad_init(void) g_has_haptic = true; #endif + memset(g_pads, 0, sizeof(g_pads)); + unsigned num_sticks = SDL_NumJoysticks(); if (num_sticks > MAX_PLAYERS) num_sticks = MAX_PLAYERS; for (i = 0; i < num_sticks; i++) - sdl_joypad_connect(i); + pad_connect(i); #ifndef HAVE_SDL2 /* quit if no joypad is detected. */ @@ -180,7 +253,7 @@ static bool sdl_joypad_button(unsigned port, uint16_t joykey) if (joykey == NO_BTN) return false; - const sdl_joypad_t *pad = &g_pads[port]; + sdl_joypad_t *pad = &g_pads[port]; if (!pad->joypad) return false; @@ -191,7 +264,7 @@ static bool sdl_joypad_button(unsigned port, uint16_t joykey) if (hat >= pad->num_hats) return false; - Uint8 dir = SDL_JoystickGetHat(pad->joypad, hat); + Uint8 dir = pad_get_hat(pad, hat); switch (GET_HAT_DIR(joykey)) { case HAT_UP_MASK: @@ -208,7 +281,7 @@ static bool sdl_joypad_button(unsigned port, uint16_t joykey) } else // Check the button { - if (joykey < pad->num_buttons && SDL_JoystickGetButton(pad->joypad, joykey)) + if (joykey < pad->num_buttons && pad_get_button(pad, joykey)) return true; return false; @@ -220,14 +293,14 @@ static int16_t sdl_joypad_axis(unsigned port, uint32_t joyaxis) if (joyaxis == AXIS_NONE) return 0; - const sdl_joypad_t *pad = &g_pads[port]; + sdl_joypad_t *pad = &g_pads[port]; if (!pad->joypad) return false; - Sint16 val = 0; + int16_t val = 0; if (AXIS_NEG_GET(joyaxis) < pad->num_axes) { - val = SDL_JoystickGetAxis(pad->joypad, AXIS_NEG_GET(joyaxis)); + val = pad_get_axis(pad, AXIS_NEG_GET(joyaxis)); if (val > 0) val = 0; @@ -236,7 +309,7 @@ static int16_t sdl_joypad_axis(unsigned port, uint32_t joyaxis) } else if (AXIS_POS_GET(joyaxis) < pad->num_axes) { - val = SDL_JoystickGetAxis(pad->joypad, AXIS_POS_GET(joyaxis)); + val = pad_get_axis(pad, AXIS_POS_GET(joyaxis)); if (val < 0) val = 0; @@ -255,11 +328,11 @@ static void sdl_joypad_poll(void) { if (event.type == SDL_JOYDEVICEADDED) { - sdl_joypad_connect(event.jdevice.which); + pad_connect(event.jdevice.which); } else if (event.type == SDL_JOYDEVICEREMOVED) { - sdl_joypad_disconnect(event.jdevice.which); + pad_disconnect(event.jdevice.which); } } #else @@ -327,11 +400,7 @@ static const char *sdl_joypad_name(unsigned pad) if (pad >= MAX_PLAYERS) return NULL; -#ifdef HAVE_SDL2 - return SDL_JoystickName(g_pads[pad].joypad); -#else - return SDL_JoystickName(pad); -#endif + return pad_name(pad); } const rarch_joypad_driver_t sdl_joypad = { From f854449d47a7c91ca21a513f23e054ae48b9e0d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Higor=20Eur=C3=ADpedes?= Date: Fri, 15 Aug 2014 22:18:46 -0300 Subject: [PATCH 6/8] (SDL*) Add joypad auto configuration support --- input/sdl_joypad.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/input/sdl_joypad.c b/input/sdl_joypad.c index 8dde5f8056..84342672a9 100644 --- a/input/sdl_joypad.c +++ b/input/sdl_joypad.c @@ -120,6 +120,9 @@ static void pad_connect(unsigned id) return; } + strlcpy(g_settings.input.device_names[id], pad_name(id), sizeof(g_settings.input.device_names[id])); + input_config_autoconfigure_joypad(id, pad_name(id), sdl_joypad.ident); + RARCH_LOG("[SDL]: Joypad #%u connected: %s.\n", id, pad_name(id)); #ifdef HAVE_SDL2 @@ -185,6 +188,8 @@ static void pad_disconnect(unsigned id) RARCH_LOG("[SDL]: Joypad #%u disconnected.\n", id); } + g_settings.input.device_names[id][0] = '\0'; + memset(&g_pads[id], 0, sizeof(g_pads[id])); } From 705f14a8daec3ca53712d733554a4f39b7da5753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Higor=20Eur=C3=ADpedes?= Date: Tue, 19 Aug 2014 15:17:56 -0300 Subject: [PATCH 7/8] (SDL2) Show available video drivers and fix typo --- gfx/sdl2_gfx.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gfx/sdl2_gfx.c b/gfx/sdl2_gfx.c index 215e86da47..9c81886468 100644 --- a/gfx/sdl2_gfx.c +++ b/gfx/sdl2_gfx.c @@ -381,19 +381,19 @@ static void *sdl2_gfx_init(const video_info_t *video, const input_driver_t **inp if (!vid) return NULL; -// RARCH_LOG("[SDL]: supported video drivers (change with $SDL_VIDEODRIVER):\n"); + RARCH_LOG("[SDL]: supported video drivers (change with $SDL_VIDEODRIVER):\n"); -// for (i = 0; i < SDL_GetNumVideoDrivers(); ++i) -// { -// RARCH_LOG("\t%s\n", SDL_GetVideoDriver(i)); -// } + for (i = 0; i < SDL_GetNumVideoDrivers(); ++i) + { + RARCH_LOG("\t%s\n", SDL_GetVideoDriver(i)); + } RARCH_LOG("[SDL]: Available displays:\n"); for(i = 0; i < SDL_GetNumVideoDisplays(); ++i) { SDL_DisplayMode mode; - if (SDL_GetCurrentDisplayMode(i, &mode) == 0) + if (SDL_GetCurrentDisplayMode(i, &mode) <= 0) RARCH_LOG("\tDisplay #%i mode: unknown.\n", i); else RARCH_LOG("\tDisplay #%i mode: %ix%i@%ihz.\n", i, mode.w, mode.h, From 3f60f7de0f54663215364bfac0940d4fabfc7426 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Higor=20Eur=C3=ADpedes?= Date: Tue, 19 Aug 2014 16:55:29 -0300 Subject: [PATCH 8/8] (SDL2) Remove double header inclusion --- gfx/sdl2_gfx.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/gfx/sdl2_gfx.c b/gfx/sdl2_gfx.c index 9c81886468..199b251883 100644 --- a/gfx/sdl2_gfx.c +++ b/gfx/sdl2_gfx.c @@ -32,8 +32,6 @@ #include "config.h" #endif -#include "SDL2/SDL_syswm.h" - typedef struct sdl2_tex { SDL_Texture *tex;