diff --git a/frontend/frontend.c b/frontend/frontend.c index 5b161db490..8c3ab8ab8f 100644 --- a/frontend/frontend.c +++ b/frontend/frontend.c @@ -21,12 +21,6 @@ #include "frontend_context.h" frontend_ctx_driver_t *frontend_ctx; -#if defined(__APPLE__) -#include -#include -#include "../apple/RetroArch/rarch_wrapper.h" -#endif - #if defined(HAVE_RGUI) || defined(HAVE_RMENU) || defined(HAVE_RMENU_XUI) #define HAVE_MENU #else @@ -146,56 +140,6 @@ static void rarch_get_environment(int argc, char *argv[]) } #if defined(__APPLE__) -static pthread_mutex_t apple_event_queue_lock = PTHREAD_MUTEX_INITIALIZER; - -static struct -{ - void (*function)(void*); - void* userdata; -} apple_event_queue[16]; - -static uint32_t apple_event_queue_size; - -void apple_frontend_post_event(void (*fn)(void*), void* userdata) -{ - pthread_mutex_lock(&apple_event_queue_lock); - - if (apple_event_queue_size < 16) - { - apple_event_queue[apple_event_queue_size].function = fn; - apple_event_queue[apple_event_queue_size].userdata = userdata; - apple_event_queue_size ++; - } - - pthread_mutex_unlock(&apple_event_queue_lock); -} - -static void apple_free_main_wrap(struct rarch_main_wrap* wrap) -{ - if (wrap) - { - free((char*)wrap->libretro_path); - free((char*)wrap->rom_path); - free((char*)wrap->sram_path); - free((char*)wrap->state_path); - free((char*)wrap->config_path); - } - - free(wrap); -} - -static void process_events(void) -{ - pthread_mutex_lock(&apple_event_queue_lock); - - for (int i = 0; i < apple_event_queue_size; i ++) - apple_event_queue[i].function(apple_event_queue[i].userdata); - - apple_event_queue_size = 0; - - pthread_mutex_unlock(&apple_event_queue_lock); -} - void* rarch_main(void* args) #else int rarch_main(int argc, char *argv[]) @@ -273,11 +217,9 @@ int rarch_main(int argc, char *argv[]) #if defined(RARCH_CONSOLE) || defined(__QNX__) g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU); #else -#if defined(__APPLE__) - // This needs to be here to tell the GUI thread that the emulator loop has stopped, - // the (void*)1 makes it display the 'Failed to load game' message. - dispatch_async_f(dispatch_get_main_queue(), (void*)1, apple_rarch_exited); -#endif + if (frontend_ctx && frontend_ctx->shutdown) + frontend_ctx->shutdown(true); + return 1; #endif } @@ -294,9 +236,8 @@ int rarch_main(int argc, char *argv[]) while ((g_extern.is_paused && !g_extern.is_oneshot) ? rarch_main_idle_iterate() : rarch_main_iterate()) { -#if defined(__APPLE__) - process_events(); -#endif + if (frontend_ctx && frontend_ctx->process_events) + frontend_ctx->process_events(); if (!(g_extern.lifecycle_mode_state & (1ULL << MODE_GAME))) break; @@ -314,9 +255,8 @@ int rarch_main(int argc, char *argv[]) while (!g_extern.system.shutdown && menu_iterate()) { -#if defined(__APPLE__) - process_events(); -#endif + if (frontend_ctx && frontend_ctx->process_events) + frontend_ctx->process_events(); if (!(g_extern.lifecycle_mode_state & (1ULL << MODE_MENU))) break; @@ -382,11 +322,7 @@ int rarch_main(int argc, char *argv[]) rarch_main_clear_state(); if (frontend_ctx && frontend_ctx->shutdown) - frontend_ctx->shutdown(true); - -#if defined(__APPLE__) - dispatch_async_f(dispatch_get_main_queue(), 0, apple_rarch_exited); -#endif + frontend_ctx->shutdown(false); return 0; } diff --git a/frontend/frontend_context.c b/frontend/frontend_context.c index 1b51d9a90f..24fa1dd161 100644 --- a/frontend/frontend_context.c +++ b/frontend/frontend_context.c @@ -33,6 +33,9 @@ static const frontend_ctx_driver_t *frontend_ctx_drivers[] = { #if defined(__QNX__) &frontend_ctx_qnx, #endif +#if defined(IOS) || defined(OSX) + &frontend_ctx_apple, +#endif }; const frontend_ctx_driver_t *frontend_ctx_find_driver(const char *ident) diff --git a/frontend/frontend_context.h b/frontend/frontend_context.h index 19c42c8934..f5334412c6 100644 --- a/frontend/frontend_context.h +++ b/frontend/frontend_context.h @@ -50,6 +50,7 @@ extern const frontend_ctx_driver_t frontend_ctx_gx; extern const frontend_ctx_driver_t frontend_ctx_ps3; extern const frontend_ctx_driver_t frontend_ctx_xdk; extern const frontend_ctx_driver_t frontend_ctx_qnx; +extern const frontend_ctx_driver_t frontend_ctx_apple; const frontend_ctx_driver_t *frontend_ctx_find_driver(const char *ident); // Finds driver with ident. Does not initialize. const frontend_ctx_driver_t *frontend_ctx_init_first(void); // Finds first suitable driver and initializes. diff --git a/frontend/platform/platform_apple.c b/frontend/platform/platform_apple.c new file mode 100644 index 0000000000..49f0b418c7 --- /dev/null +++ b/frontend/platform/platform_apple.c @@ -0,0 +1,95 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2013 - Hans-Kristian Arntzen + * Copyright (C) 2011-2013 - 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 . + */ + +#include +#include +#include "../apple/RetroArch/rarch_wrapper.h" + +#include +#include "../../boolean.h" +#include +#include + +static pthread_mutex_t apple_event_queue_lock = PTHREAD_MUTEX_INITIALIZER; + +static struct +{ + void (*function)(void*); + void* userdata; +} apple_event_queue[16]; + +static uint32_t apple_event_queue_size; + +void apple_frontend_post_event(void (*fn)(void*), void* userdata) +{ + pthread_mutex_lock(&apple_event_queue_lock); + + if (apple_event_queue_size < 16) + { + apple_event_queue[apple_event_queue_size].function = fn; + apple_event_queue[apple_event_queue_size].userdata = userdata; + apple_event_queue_size ++; + } + + pthread_mutex_unlock(&apple_event_queue_lock); +} + +static void apple_free_main_wrap(struct rarch_main_wrap* wrap) +{ + if (wrap) + { + free((char*)wrap->libretro_path); + free((char*)wrap->rom_path); + free((char*)wrap->sram_path); + free((char*)wrap->state_path); + free((char*)wrap->config_path); + } + + free(wrap); +} + +static void process_events(void) +{ + pthread_mutex_lock(&apple_event_queue_lock); + + for (int i = 0; i < apple_event_queue_size; i ++) + apple_event_queue[i].function(apple_event_queue[i].userdata); + + apple_event_queue_size = 0; + + pthread_mutex_unlock(&apple_event_queue_lock); +} + +static void system_shutdown(bool force) +{ + /* force set to true makes it display the 'Failed to load game' message. */ + if (force) + dispatch_async_f(dispatch_get_main_queue(), (void*)1, apple_rarch_exited); + else + dispatch_async_f(dispatch_get_main_queue(), 0, apple_rarch_exited); +} + +const frontend_ctx_driver_t frontend_ctx_apple = { + NULL, /* get_environment_settings */ + NULL, /* init */ + NULL, /* deinit */ + NULL, /* exitspawn */ + NULL, /* process_args */ + process_events, /* process_events */ + NULL, /* exec */ + system_shutdown, /* shutdown */ + "apple", +}; diff --git a/griffin/griffin.c b/griffin/griffin.c index 3ccaaea4b0..83a206f2d1 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -458,6 +458,8 @@ FRONTEND #include "../frontend/platform/platform_psp.c" #elif defined(__QNX__) #include "../frontend/platform/platform_qnx.c" +#elif defined(OSX) || defined(IOS) +#include "../frontend/platform/platform_apple.c" #endif /*============================================================