From 619c96187b1c661677e5b47b6752e7166d4b08f1 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 26 May 2014 19:00:55 +0200 Subject: [PATCH] (Driver.c) driver.c was a big mess - split up into separate files that get included in. Should probably be properly refactored later on for all targets so that each included file becomes its own object file --- driver-contexts/camera_driver.c | 133 ++++++++++ driver-contexts/location_driver.c | 132 ++++++++++ driver-contexts/menu_driver.c | 100 ++++++++ driver-contexts/osk_driver.c | 90 +++++++ driver.c | 414 +----------------------------- 5 files changed, 461 insertions(+), 408 deletions(-) create mode 100644 driver-contexts/camera_driver.c create mode 100644 driver-contexts/location_driver.c create mode 100644 driver-contexts/menu_driver.c create mode 100644 driver-contexts/osk_driver.c diff --git a/driver-contexts/camera_driver.c b/driver-contexts/camera_driver.c new file mode 100644 index 0000000000..be4a88ce06 --- /dev/null +++ b/driver-contexts/camera_driver.c @@ -0,0 +1,133 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2014 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +static const camera_driver_t *camera_drivers[] = { +#ifdef HAVE_V4L2 + &camera_v4l2, +#endif +#ifdef EMSCRIPTEN + &camera_rwebcam, +#endif +#ifdef ANDROID + &camera_android, +#endif +#ifdef IOS + &camera_ios, +#endif + NULL, +}; + +static int find_camera_driver_index(const char *driver) +{ + unsigned i; + for (i = 0; camera_drivers[i]; i++) + if (strcasecmp(driver, camera_drivers[i]->ident) == 0) + return i; + return -1; +} + +static void find_camera_driver(void) +{ + int i = find_camera_driver_index(g_settings.camera.driver); + if (i >= 0) + driver.camera = camera_drivers[i]; + else + { + unsigned d; + RARCH_ERR("Couldn't find any camera driver named \"%s\"\n", g_settings.camera.driver); + RARCH_LOG_OUTPUT("Available camera drivers are:\n"); + for (d = 0; camera_drivers[d]; d++) + RARCH_LOG_OUTPUT("\t%s\n", camera_drivers[d]->ident); + + rarch_fail(1, "find_camera_driver()"); + } +} + +void find_prev_camera_driver(void) +{ + int i = find_camera_driver_index(g_settings.camera.driver); + if (i > 0) + strlcpy(g_settings.camera.driver, camera_drivers[i - 1]->ident, sizeof(g_settings.camera.driver)); + else + RARCH_WARN("Couldn't find any previous camera driver (current one: \"%s\").\n", g_settings.camera.driver); +} + +void find_next_camera_driver(void) +{ + int i = find_camera_driver_index(g_settings.camera.driver); + if (i >= 0 && camera_drivers[i + 1]) + strlcpy(g_settings.camera.driver, camera_drivers[i + 1]->ident, sizeof(g_settings.camera.driver)); + else + RARCH_WARN("Couldn't find any next camera driver (current one: \"%s\").\n", g_settings.camera.driver); +} + +bool driver_camera_start(void) +{ + if (driver.camera && driver.camera_data && g_settings.camera.allow) + return driver.camera->start(driver.camera_data); + else + return false; +} + +void driver_camera_stop(void) +{ + if (driver.camera && driver.camera_data) + driver.camera->stop(driver.camera_data); +} + +void driver_camera_poll(void) +{ + if (driver.camera && driver.camera_data) + { + driver.camera->poll(driver.camera_data, + g_extern.system.camera_callback.frame_raw_framebuffer, + g_extern.system.camera_callback.frame_opengl_texture); + } +} + +void init_camera(void) +{ + // Resource leaks will follow if camera is initialized twice. + if (driver.camera_data) + return; + + find_camera_driver(); + + driver.camera_data = camera_init_func( + *g_settings.camera.device ? g_settings.camera.device : NULL, + g_extern.system.camera_callback.caps, + g_settings.camera.width ? g_settings.camera.width : g_extern.system.camera_callback.width, + g_settings.camera.height ? g_settings.camera.height : g_extern.system.camera_callback.height); + + if (!driver.camera_data) + { + RARCH_ERR("Failed to initialize camera driver. Will continue without camera.\n"); + g_extern.camera_active = false; + } + + if (g_extern.system.camera_callback.initialized) + g_extern.system.camera_callback.initialized(); +} + +void uninit_camera(void) +{ + if (driver.camera_data && driver.camera) + { + if (g_extern.system.camera_callback.deinitialized) + g_extern.system.camera_callback.deinitialized(); + driver.camera->free(driver.camera_data); + } +} diff --git a/driver-contexts/location_driver.c b/driver-contexts/location_driver.c new file mode 100644 index 0000000000..7ecda009c6 --- /dev/null +++ b/driver-contexts/location_driver.c @@ -0,0 +1,132 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2014 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +static const location_driver_t *location_drivers[] = { +#ifdef ANDROID + &location_android, +#endif +#if defined(IOS) || defined(OSX) + &location_apple, +#endif + NULL, +}; + +static int find_location_driver_index(const char *driver) +{ + unsigned i; + for (i = 0; location_drivers[i]; i++) + if (strcasecmp(driver, location_drivers[i]->ident) == 0) + return i; + return -1; +} + +static void find_location_driver(void) +{ + int i = find_location_driver_index(g_settings.location.driver); + if (i >= 0) + driver.location = location_drivers[i]; + else + { + unsigned d; + RARCH_ERR("Couldn't find any location driver named \"%s\"\n", g_settings.location.driver); + RARCH_LOG_OUTPUT("Available location drivers are:\n"); + for (d = 0; location_drivers[d]; d++) + RARCH_LOG_OUTPUT("\t%s\n", location_drivers[d]->ident); + + rarch_fail(1, "find_location_driver()"); + } +} + +void find_prev_location_driver(void) +{ + int i = find_location_driver_index(g_settings.location.driver); + if (i > 0) + strlcpy(g_settings.location.driver, location_drivers[i - 1]->ident, sizeof(g_settings.location.driver)); + else + RARCH_WARN("Couldn't find any previous location driver (current one: \"%s\").\n", g_settings.location.driver); +} + +void find_next_location_driver(void) +{ + int i = find_location_driver_index(g_settings.location.driver); + if (i >= 0 && location_drivers[i + 1]) + strlcpy(g_settings.location.driver, location_drivers[i + 1]->ident, sizeof(g_settings.location.driver)); + else + RARCH_WARN("Couldn't find any next location driver (current one: \"%s\").\n", g_settings.location.driver); +} + +bool driver_location_start(void) +{ + if (driver.location && driver.location_data && g_settings.location.allow) + return driver.location->start(driver.location_data); + else + return false; +} + +void driver_location_stop(void) +{ + if (driver.location && driver.location_data) + driver.location->stop(driver.location_data); +} + +void driver_location_set_interval(unsigned interval_msecs, unsigned interval_distance) +{ + if (driver.location && driver.location_data) + driver.location->set_interval(driver.location_data, interval_msecs, interval_distance); +} + +bool driver_location_get_position(double *lat, double *lon, double *horiz_accuracy, + double *vert_accuracy) +{ + if (driver.location && driver.location_data) + return driver.location->get_position(driver.location_data, lat, lon, horiz_accuracy, vert_accuracy); + + *lat = 0.0; + *lon = 0.0; + *horiz_accuracy = 0.0; + *vert_accuracy = 0.0; + return false; +} + +void init_location(void) +{ + // Resource leaks will follow if location interface is initialized twice. + if (driver.location_data) + return; + + find_location_driver(); + + driver.location_data = location_init_func(); + + if (!driver.location_data) + { + RARCH_ERR("Failed to initialize location driver. Will continue without location.\n"); + g_extern.location_active = false; + } + + if (g_extern.system.location_callback.initialized) + g_extern.system.location_callback.initialized(); +} + +void uninit_location(void) +{ + if (driver.location_data && driver.location) + { + if (g_extern.system.location_callback.deinitialized) + g_extern.system.location_callback.deinitialized(); + driver.location->free(driver.location_data); + } +} diff --git a/driver-contexts/menu_driver.c b/driver-contexts/menu_driver.c new file mode 100644 index 0000000000..1e6dca6322 --- /dev/null +++ b/driver-contexts/menu_driver.c @@ -0,0 +1,100 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2014 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +static const menu_ctx_driver_t *menu_ctx_drivers[] = { +#if defined(HAVE_RMENU) + &menu_ctx_rmenu, +#endif +#if defined(HAVE_RMENU_XUI) + &menu_ctx_rmenu_xui, +#endif +#if defined(HAVE_LAKKA) + &menu_ctx_lakka, +#endif +#if defined(HAVE_RGUI) + &menu_ctx_rgui, +#endif + + NULL // zero length array is not valid +}; + +const void *menu_ctx_find_driver(const char *ident) +{ + unsigned i; + for (i = 0; menu_ctx_drivers[i]; i++) + { + if (strcmp(menu_ctx_drivers[i]->ident, ident) == 0) + return menu_ctx_drivers[i]; + } + + return NULL; +} + +static int find_menu_driver_index(const char *driver) +{ + unsigned i; + for (i = 0; menu_ctx_drivers[i]; i++) + if (strcasecmp(driver, menu_ctx_drivers[i]->ident) == 0) + return i; + return -1; +} + +void find_prev_menu_driver(void) +{ + int i = find_menu_driver_index(g_settings.menu.driver); + if (i > 0) + { + strlcpy(g_settings.menu.driver, menu_ctx_drivers[i - 1]->ident, sizeof(g_settings.menu.driver)); + driver.menu_ctx = (menu_ctx_driver_t*)menu_ctx_drivers[i - 1]; + } + else + RARCH_WARN("Couldn't find any previous menu driver (current one: \"%s\").\n", g_settings.menu.driver); +} + +void find_next_menu_driver(void) +{ + int i = find_menu_driver_index(g_settings.menu.driver); + if (i >= 0 && menu_ctx_drivers[i + 1]) + { + strlcpy(g_settings.menu.driver, menu_ctx_drivers[i + 1]->ident, sizeof(g_settings.menu.driver)); + driver.menu_ctx = (menu_ctx_driver_t*)menu_ctx_drivers[i + 1]; + } + else + RARCH_WARN("Couldn't find any next menu driver (current one: \"%s\").\n", g_settings.menu.driver); +} + +bool menu_ctx_init_first(const menu_ctx_driver_t **driver, void **data) +{ + unsigned i; + + if (!menu_ctx_drivers[0]) + return false; + + for (i = 0; menu_ctx_drivers[i]; i++) + { + void *h = menu_ctx_drivers[i]->init(); + + if (h) + { + *driver = menu_ctx_drivers[i]; + *data = h; + strlcpy(g_settings.menu.driver, menu_ctx_drivers[i]->ident, sizeof(g_settings.menu.driver)); + return true; + } + } + + return false; +} diff --git a/driver-contexts/osk_driver.c b/driver-contexts/osk_driver.c new file mode 100644 index 0000000000..28729deb6e --- /dev/null +++ b/driver-contexts/osk_driver.c @@ -0,0 +1,90 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2014 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +static const input_osk_driver_t *osk_drivers[] = { +#ifdef __CELLOS_LV2__ + &input_ps3_osk, +#endif + NULL, +}; + +static int find_osk_driver_index(const char *driver) +{ + unsigned i; + for (i = 0; osk_drivers[i]; i++) + if (strcasecmp(driver, osk_drivers[i]->ident) == 0) + return i; + return -1; +} + +static void find_osk_driver(void) +{ + int i = find_osk_driver_index(g_settings.osk.driver); + if (i >= 0) + driver.osk = osk_drivers[i]; + else + { + unsigned d; + RARCH_ERR("Couldn't find any OSK driver named \"%s\"\n", g_settings.osk.driver); + RARCH_LOG_OUTPUT("Available OSK drivers are:\n"); + for (d = 0; osk_drivers[d]; d++) + RARCH_LOG_OUTPUT("\t%s\n", osk_drivers[d]->ident); + + rarch_fail(1, "find_osk_driver()"); + } +} + +void find_prev_osk_driver(void) +{ + int i = find_osk_driver_index(g_settings.osk.driver); + if (i > 0) + strlcpy(g_settings.osk.driver, osk_drivers[i - 1]->ident, sizeof(g_settings.osk.driver)); + else + RARCH_WARN("Couldn't find any previous osk driver (current one: \"%s\").\n", g_settings.osk.driver); +} + +void find_next_osk_driver(void) +{ + int i = find_osk_driver_index(g_settings.osk.driver); + if (i >= 0 && osk_drivers[i + 1]) + strlcpy(g_settings.osk.driver, osk_drivers[i + 1]->ident, sizeof(g_settings.osk.driver)); + else + RARCH_WARN("Couldn't find any next osk driver (current one: \"%s\").\n", g_settings.osk.driver); +} + +void init_osk(void) +{ + // Resource leaks will follow if osk is initialized twice. + if (driver.osk_data) + return; + + find_osk_driver(); + + //FIXME - refactor params later based on semantics + driver.osk_data = osk_init_func(0); + + if (!driver.osk_data) + { + RARCH_ERR("Failed to initialize OSK driver. Will continue without OSK.\n"); + g_extern.osk_active = false; + } +} + +void uninit_osk(void) +{ + if (driver.osk_data && driver.osk) + driver.osk->free(driver.osk_data); +} diff --git a/driver.c b/driver.c index 06c67baa6a..b2beebb538 100644 --- a/driver.c +++ b/driver.c @@ -1,5 +1,6 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2014 - Daniel De Matteis * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- @@ -188,174 +189,19 @@ static const input_driver_t *input_drivers[] = { }; #ifdef HAVE_OSK -static const input_osk_driver_t *osk_drivers[] = { -#ifdef __CELLOS_LV2__ - &input_ps3_osk, -#endif - NULL, -}; - -static int find_osk_driver_index(const char *driver) -{ - unsigned i; - for (i = 0; osk_drivers[i]; i++) - if (strcasecmp(driver, osk_drivers[i]->ident) == 0) - return i; - return -1; -} - -static void find_osk_driver(void) -{ - int i = find_osk_driver_index(g_settings.osk.driver); - if (i >= 0) - driver.osk = osk_drivers[i]; - else - { - unsigned d; - RARCH_ERR("Couldn't find any OSK driver named \"%s\"\n", g_settings.osk.driver); - RARCH_LOG_OUTPUT("Available OSK drivers are:\n"); - for (d = 0; osk_drivers[d]; d++) - RARCH_LOG_OUTPUT("\t%s\n", osk_drivers[d]->ident); - - rarch_fail(1, "find_osk_driver()"); - } -} - -void find_prev_osk_driver(void) -{ - int i = find_osk_driver_index(g_settings.osk.driver); - if (i > 0) - strlcpy(g_settings.osk.driver, osk_drivers[i - 1]->ident, sizeof(g_settings.osk.driver)); - else - RARCH_WARN("Couldn't find any previous osk driver (current one: \"%s\").\n", g_settings.osk.driver); -} - -void find_next_osk_driver(void) -{ - int i = find_osk_driver_index(g_settings.osk.driver); - if (i >= 0 && osk_drivers[i + 1]) - strlcpy(g_settings.osk.driver, osk_drivers[i + 1]->ident, sizeof(g_settings.osk.driver)); - else - RARCH_WARN("Couldn't find any next osk driver (current one: \"%s\").\n", g_settings.osk.driver); -} +#include "driver-contexts/osk_driver.c" #endif #ifdef HAVE_CAMERA -static const camera_driver_t *camera_drivers[] = { -#ifdef HAVE_V4L2 - &camera_v4l2, -#endif -#ifdef EMSCRIPTEN - &camera_rwebcam, -#endif -#ifdef ANDROID - &camera_android, -#endif -#ifdef IOS - &camera_ios, -#endif - NULL, -}; - -static int find_camera_driver_index(const char *driver) -{ - unsigned i; - for (i = 0; camera_drivers[i]; i++) - if (strcasecmp(driver, camera_drivers[i]->ident) == 0) - return i; - return -1; -} - -static void find_camera_driver(void) -{ - int i = find_camera_driver_index(g_settings.camera.driver); - if (i >= 0) - driver.camera = camera_drivers[i]; - else - { - unsigned d; - RARCH_ERR("Couldn't find any camera driver named \"%s\"\n", g_settings.camera.driver); - RARCH_LOG_OUTPUT("Available camera drivers are:\n"); - for (d = 0; camera_drivers[d]; d++) - RARCH_LOG_OUTPUT("\t%s\n", camera_drivers[d]->ident); - - rarch_fail(1, "find_camera_driver()"); - } -} - -void find_prev_camera_driver(void) -{ - int i = find_camera_driver_index(g_settings.camera.driver); - if (i > 0) - strlcpy(g_settings.camera.driver, camera_drivers[i - 1]->ident, sizeof(g_settings.camera.driver)); - else - RARCH_WARN("Couldn't find any previous camera driver (current one: \"%s\").\n", g_settings.camera.driver); -} - -void find_next_camera_driver(void) -{ - int i = find_camera_driver_index(g_settings.camera.driver); - if (i >= 0 && camera_drivers[i + 1]) - strlcpy(g_settings.camera.driver, camera_drivers[i + 1]->ident, sizeof(g_settings.camera.driver)); - else - RARCH_WARN("Couldn't find any next camera driver (current one: \"%s\").\n", g_settings.camera.driver); -} +#include "driver-contexts/camera_driver.c" #endif #ifdef HAVE_LOCATION -static const location_driver_t *location_drivers[] = { -#ifdef ANDROID - &location_android, +#include "driver-contexts/location_driver.c" #endif -#if defined(IOS) || defined(OSX) - &location_apple, -#endif - NULL, -}; -static int find_location_driver_index(const char *driver) -{ - unsigned i; - for (i = 0; location_drivers[i]; i++) - if (strcasecmp(driver, location_drivers[i]->ident) == 0) - return i; - return -1; -} - -static void find_location_driver(void) -{ - int i = find_location_driver_index(g_settings.location.driver); - if (i >= 0) - driver.location = location_drivers[i]; - else - { - unsigned d; - RARCH_ERR("Couldn't find any location driver named \"%s\"\n", g_settings.location.driver); - RARCH_LOG_OUTPUT("Available location drivers are:\n"); - for (d = 0; location_drivers[d]; d++) - RARCH_LOG_OUTPUT("\t%s\n", location_drivers[d]->ident); - - rarch_fail(1, "find_location_driver()"); - } -} - -void find_prev_location_driver(void) -{ - int i = find_location_driver_index(g_settings.location.driver); - if (i > 0) - strlcpy(g_settings.location.driver, location_drivers[i - 1]->ident, sizeof(g_settings.location.driver)); - else - RARCH_WARN("Couldn't find any previous location driver (current one: \"%s\").\n", g_settings.location.driver); -} - -void find_next_location_driver(void) -{ - int i = find_location_driver_index(g_settings.location.driver); - if (i >= 0 && location_drivers[i + 1]) - strlcpy(g_settings.location.driver, location_drivers[i + 1]->ident, sizeof(g_settings.location.driver)); - else - RARCH_WARN("Couldn't find any next location driver (current one: \"%s\").\n", g_settings.location.driver); -} +#ifdef HAVE_MENU +#include "driver-contexts/menu_driver.c" #endif static int find_audio_driver_index(const char *driver) @@ -614,67 +460,6 @@ float driver_sensor_get_input(unsigned port, unsigned id) return 0.0f; } -#ifdef HAVE_CAMERA -bool driver_camera_start(void) -{ - if (driver.camera && driver.camera_data && g_settings.camera.allow) - return driver.camera->start(driver.camera_data); - else - return false; -} - -void driver_camera_stop(void) -{ - if (driver.camera && driver.camera_data) - driver.camera->stop(driver.camera_data); -} - -void driver_camera_poll(void) -{ - if (driver.camera && driver.camera_data) - { - driver.camera->poll(driver.camera_data, - g_extern.system.camera_callback.frame_raw_framebuffer, - g_extern.system.camera_callback.frame_opengl_texture); - } -} -#endif - -#ifdef HAVE_LOCATION -bool driver_location_start(void) -{ - if (driver.location && driver.location_data && g_settings.location.allow) - return driver.location->start(driver.location_data); - else - return false; -} - -void driver_location_stop(void) -{ - if (driver.location && driver.location_data) - driver.location->stop(driver.location_data); -} - -void driver_location_set_interval(unsigned interval_msecs, unsigned interval_distance) -{ - if (driver.location && driver.location_data) - driver.location->set_interval(driver.location_data, interval_msecs, interval_distance); -} - -bool driver_location_get_position(double *lat, double *lon, double *horiz_accuracy, - double *vert_accuracy) -{ - if (driver.location && driver.location_data) - return driver.location->get_position(driver.location_data, lat, lon, horiz_accuracy, vert_accuracy); - - *lat = 0.0; - *lon = 0.0; - *horiz_accuracy = 0.0; - *vert_accuracy = 0.0; - return false; -} -#endif - uintptr_t driver_get_current_framebuffer(void) { #ifdef HAVE_FBO @@ -769,74 +554,6 @@ void global_uninit_drivers(void) #endif } -#ifdef HAVE_CAMERA -void init_camera(void) -{ - // Resource leaks will follow if camera is initialized twice. - if (driver.camera_data) - return; - - find_camera_driver(); - - driver.camera_data = camera_init_func( - *g_settings.camera.device ? g_settings.camera.device : NULL, - g_extern.system.camera_callback.caps, - g_settings.camera.width ? g_settings.camera.width : g_extern.system.camera_callback.width, - g_settings.camera.height ? g_settings.camera.height : g_extern.system.camera_callback.height); - - if (!driver.camera_data) - { - RARCH_ERR("Failed to initialize camera driver. Will continue without camera.\n"); - g_extern.camera_active = false; - } - - if (g_extern.system.camera_callback.initialized) - g_extern.system.camera_callback.initialized(); -} -#endif - -#ifdef HAVE_LOCATION -void init_location(void) -{ - // Resource leaks will follow if location interface is initialized twice. - if (driver.location_data) - return; - - find_location_driver(); - - driver.location_data = location_init_func(); - - if (!driver.location_data) - { - RARCH_ERR("Failed to initialize location driver. Will continue without location.\n"); - g_extern.location_active = false; - } - - if (g_extern.system.location_callback.initialized) - g_extern.system.location_callback.initialized(); -} -#endif - -#ifdef HAVE_OSK -void init_osk(void) -{ - // Resource leaks will follow if osk is initialized twice. - if (driver.osk_data) - return; - - find_osk_driver(); - - //FIXME - refactor params later based on semantics - driver.osk_data = osk_init_func(0); - - if (!driver.osk_data) - { - RARCH_ERR("Failed to initialize OSK driver. Will continue without OSK.\n"); - g_extern.osk_active = false; - } -} -#endif - void init_drivers(void) { driver.video_data_own = !driver.video_data; @@ -886,38 +603,6 @@ void init_drivers(void) g_extern.system.frame_time_last = 0; } -#ifdef HAVE_CAMERA -void uninit_camera(void) -{ - if (driver.camera_data && driver.camera) - { - if (g_extern.system.camera_callback.deinitialized) - g_extern.system.camera_callback.deinitialized(); - driver.camera->free(driver.camera_data); - } -} -#endif - -#ifdef HAVE_LOCATION -void uninit_location(void) -{ - if (driver.location_data && driver.location) - { - if (g_extern.system.location_callback.deinitialized) - g_extern.system.location_callback.deinitialized(); - driver.location->free(driver.location_data); - } -} -#endif - -#ifdef HAVE_OSK -void uninit_osk(void) -{ - if (driver.osk_data && driver.osk) - driver.osk->free(driver.osk_data); -} -#endif - void uninit_drivers(void) { uninit_audio(); @@ -1555,92 +1240,5 @@ void uninit_video_input(void) compute_monitor_fps_statistics(); } -#ifdef HAVE_MENU -static const menu_ctx_driver_t *menu_ctx_drivers[] = { -#if defined(HAVE_RMENU) - &menu_ctx_rmenu, -#endif -#if defined(HAVE_RMENU_XUI) - &menu_ctx_rmenu_xui, -#endif -#if defined(HAVE_LAKKA) - &menu_ctx_lakka, -#endif -#if defined(HAVE_RGUI) - &menu_ctx_rgui, -#endif - - NULL // zero length array is not valid -}; - -const void *menu_ctx_find_driver(const char *ident) -{ - unsigned i; - for (i = 0; menu_ctx_drivers[i]; i++) - { - if (strcmp(menu_ctx_drivers[i]->ident, ident) == 0) - return menu_ctx_drivers[i]; - } - - return NULL; -} - -static int find_menu_driver_index(const char *driver) -{ - unsigned i; - for (i = 0; menu_ctx_drivers[i]; i++) - if (strcasecmp(driver, menu_ctx_drivers[i]->ident) == 0) - return i; - return -1; -} - -void find_prev_menu_driver(void) -{ - int i = find_menu_driver_index(g_settings.menu.driver); - if (i > 0) - { - strlcpy(g_settings.menu.driver, menu_ctx_drivers[i - 1]->ident, sizeof(g_settings.menu.driver)); - driver.menu_ctx = (menu_ctx_driver_t*)menu_ctx_drivers[i - 1]; - } - else - RARCH_WARN("Couldn't find any previous menu driver (current one: \"%s\").\n", g_settings.menu.driver); -} - -void find_next_menu_driver(void) -{ - int i = find_menu_driver_index(g_settings.menu.driver); - if (i >= 0 && menu_ctx_drivers[i + 1]) - { - strlcpy(g_settings.menu.driver, menu_ctx_drivers[i + 1]->ident, sizeof(g_settings.menu.driver)); - driver.menu_ctx = (menu_ctx_driver_t*)menu_ctx_drivers[i + 1]; - } - else - RARCH_WARN("Couldn't find any next menu driver (current one: \"%s\").\n", g_settings.menu.driver); -} - -bool menu_ctx_init_first(const menu_ctx_driver_t **driver, void **data) -{ - unsigned i; - - if (!menu_ctx_drivers[0]) - return false; - - for (i = 0; menu_ctx_drivers[i]; i++) - { - void *h = menu_ctx_drivers[i]->init(); - - if (h) - { - *driver = menu_ctx_drivers[i]; - *data = h; - strlcpy(g_settings.menu.driver, menu_ctx_drivers[i]->ident, sizeof(g_settings.menu.driver)); - return true; - } - } - - return false; -} -#endif - driver_t driver;