diff --git a/Makefile.common b/Makefile.common index 9a55a67774..b5e54fbec6 100644 --- a/Makefile.common +++ b/Makefile.common @@ -204,7 +204,7 @@ OBJ += frontend/frontend.o \ movie.o \ record/record_driver.o \ record/drivers/record_null.o \ - performance.o \ + libretro-common/features/features_cpu.o \ performance_counters.o \ verbosity.o @@ -291,8 +291,11 @@ ifeq ($(HAVE_OSS_BSD), 1) endif ifeq ($(HAVE_ALSA), 1) - OBJ += audio/drivers/alsa.o \ - audio/drivers/alsathread.o + OBJ += audio/drivers/alsa.o + +ifeq ($(HAVE_THREADS), 1) + OBJ += audio/drivers/alsathread.o +endif LIBS += $(ALSA_LIBS) DEFINES += $(ALSA_CFLAGS) endif @@ -575,11 +578,13 @@ ifeq ($(HAVE_UDEV), 1) endif ifeq ($(HAVE_LIBUSB), 1) +ifeq ($(HAVE_THREADS), 1) DEFINES += -DHAVE_LIBUSB OBJ += input/drivers_hid/libusb_hid.o LIBS += -lusb-1.0 HAVE_HID = 1 endif +endif ifeq ($(HAVE_IOHIDMANAGER), 1) DEFINES += -DHAVE_IOHIDMANAGER @@ -885,7 +890,6 @@ ifeq ($(HAVE_ZLIB), 1) tasks/task_decompress.o OBJ += $(ZLIB_OBJS) DEFINES += -DHAVE_ZLIB - HAVE_RPNG = 1 HAVE_COMPRESSION = 1 ifeq ($(WANT_ZLIB), 1) DEFINES += -DWANT_ZLIB @@ -895,19 +899,24 @@ ifeq ($(HAVE_ZLIB), 1) endif endif -ifdef HAVE_RPNG - DEFINES += -DHAVE_RPNG -endif - ifeq ($(HAVE_RPNG), 1) + DEFINES += -DHAVE_RPNG OBJ += libretro-common/formats/png/rpng.o \ libretro-common/formats/png/rpng_encode.o endif -OBJ += libretro-common/formats/jpeg/rjpeg.o \ - libretro-common/formats/bmp/rbmp_encode.o \ - libretro-common/formats/tga/rtga.o \ + +ifeq ($(HAVE_RJPEG), 1) + DEFINES += -DHAVE_RJPEG + OBJ += libretro-common/formats/jpeg/rjpeg.o +endif + +OBJ += libretro-common/formats/bmp/rbmp_encode.o \ libretro-common/formats/json/jsonsax.o +ifeq ($(HAVE_RTGA), 1) +OBJ += libretro-common/formats/tga/rtga.o +endif + ifdef HAVE_COMPRESSION DEFINES += -DHAVE_COMPRESSION endif diff --git a/audio/audio_driver.c b/audio/audio_driver.c index b9cd3fed4c..c875df40f1 100644 --- a/audio/audio_driver.c +++ b/audio/audio_driver.c @@ -93,7 +93,7 @@ typedef struct audio_driver_input_data static const audio_driver_t *audio_drivers[] = { #ifdef HAVE_ALSA &audio_alsa, -#ifndef __QNX__ +#if !defined(__QNX__) && defined(HAVE_THREADS) &audio_alsathread, #endif #endif diff --git a/audio/audio_dsp_filter.c b/audio/audio_dsp_filter.c index e781683918..6f49734f2e 100644 --- a/audio/audio_dsp_filter.c +++ b/audio/audio_dsp_filter.c @@ -23,13 +23,13 @@ #include #include +#include #include "audio_dsp_filter.h" #include "audio_filters/dspfilter.h" #include "../config_file_userdata.h" #include "../frontend/frontend_driver.h" -#include "../performance.h" #include "../performance_counters.h" #include "../dynamic.h" diff --git a/audio/audio_resampler_driver.c b/audio/audio_resampler_driver.c index a50d70fece..6e1f5cebb0 100644 --- a/audio/audio_resampler_driver.c +++ b/audio/audio_resampler_driver.c @@ -17,11 +17,11 @@ #include #include +#include #include "audio_resampler_driver.h" #include "../config_file_userdata.h" #ifdef RARCH_INTERNAL -#include "../performance.h" #include "../performance_counters.h" #endif #ifndef DONT_HAVE_STRING_LIST @@ -142,11 +142,7 @@ retro_get_cpu_features_t perf_get_cpu_features_cb; static resampler_simd_mask_t resampler_get_cpu_features(void) { -#ifdef RARCH_INTERNAL return cpu_features_get(); -#else - return perf_get_cpu_features_cb(); -#endif } /** diff --git a/audio/audio_resampler_driver.h b/audio/audio_resampler_driver.h index 0b1224a795..ca89c42fec 100644 --- a/audio/audio_resampler_driver.h +++ b/audio/audio_resampler_driver.h @@ -22,12 +22,13 @@ extern "C" { #endif -#include #include +#include #include -#include #include +#include +#include #define RESAMPLER_SIMD_SSE (1 << 0) #define RESAMPLER_SIMD_SSE2 (1 << 1) @@ -200,10 +201,6 @@ bool rarch_resampler_realloc(void **re, const rarch_resampler_t **backend, (backend)->process(handle, data); \ } while(0) -#ifndef RARCH_INTERNAL -#include "libretro.h" -extern retro_get_cpu_features_t perf_get_cpu_features_cb; -#endif #ifdef __cplusplus } diff --git a/audio/audio_utils.c b/audio/audio_utils.c index 51b5f9b9a1..b7cab9463a 100644 --- a/audio/audio_utils.c +++ b/audio/audio_utils.c @@ -13,18 +13,18 @@ * You should have received a copy of the GNU General Public License along with RetroArch. * If not, see . */ - -#include -#include "audio_utils.h" - #if defined(__SSE2__) #include #elif defined(__ALTIVEC__) #include #endif +#include +#include + +#include "audio_utils.h" + #ifdef RARCH_INTERNAL -#include "../performance.h" #include "../performance_counters.h" #endif diff --git a/audio/drivers/jack.c b/audio/drivers/jack.c index f9f3abfaf6..80b2ee34e3 100644 --- a/audio/drivers/jack.c +++ b/audio/drivers/jack.c @@ -41,8 +41,10 @@ typedef struct jack bool nonblock; bool is_paused; +#ifdef HAVE_THREADS scond_t *cond; slock_t *cond_lock; +#endif size_t buffer_size; } jack_t; @@ -54,7 +56,9 @@ static int process_cb(jack_nframes_t nframes, void *data) if (nframes <= 0) { +#ifdef HAVE_THREADS scond_signal(jd->cond); +#endif return 0; } @@ -74,7 +78,9 @@ static int process_cb(jack_nframes_t nframes, void *data) for (f = min_avail; f < nframes; f++) out[f] = 0.0f; } +#ifdef HAVE_THREADS scond_signal(jd->cond); +#endif return 0; } @@ -86,7 +92,9 @@ static void shutdown_cb(void *data) return; jd->shutdown = true; +#ifdef HAVE_THREADS scond_signal(jd->cond); +#endif } static int parse_ports(char **dest_ports, const char **jports) @@ -149,8 +157,10 @@ static void *ja_init(const char *device, unsigned rate, unsigned latency) if (!jd) return NULL; +#ifdef HAVE_THREADS jd->cond = scond_new(); jd->cond_lock = slock_new(); +#endif jd->client = jack_client_open("RetroArch", JackNullOption, NULL); if (jd->client == NULL) @@ -258,12 +268,14 @@ static size_t write_buffer(jack_t *jd, const float *buf, size_t size) } written += write_frames; } +#ifdef HAVE_THREADS else { slock_lock(jd->cond_lock); scond_wait(jd->cond, jd->cond_lock); slock_unlock(jd->cond_lock); } +#endif if (jd->nonblock) break; @@ -327,10 +339,12 @@ static void ja_free(void *data) if (jd->buffer[i] != NULL) jack_ringbuffer_free(jd->buffer[i]); +#ifdef HAVE_THREADS if (jd->cond_lock) slock_free(jd->cond_lock); if (jd->cond) scond_free(jd->cond); +#endif free(jd); } diff --git a/audio/drivers/sdl_audio.c b/audio/drivers/sdl_audio.c index dc6f16eb34..181d60f105 100644 --- a/audio/drivers/sdl_audio.c +++ b/audio/drivers/sdl_audio.c @@ -35,8 +35,10 @@ typedef struct sdl_audio bool nonblock; bool is_paused; +#ifdef HAVE_THREADS slock_t *lock; scond_t *cond; +#endif fifo_buffer_t *buffer; } sdl_audio_t; @@ -47,7 +49,9 @@ static void sdl_audio_cb(void *data, Uint8 *stream, int len) size_t write_size = len > (int)avail ? avail : len; fifo_read(sdl->buffer, stream, write_size); +#ifdef HAVE_THREADS scond_signal(sdl->cond); +#endif /* If underrun, fill rest with silence. */ memset(stream + write_size, 0, len - write_size); @@ -109,8 +113,10 @@ static void *sdl_audio_init(const char *device, settings->audio.out_rate = out.freq; +#ifdef HAVE_THREADS sdl->lock = slock_new(); sdl->cond = scond_new(); +#endif RARCH_LOG("SDL audio: Requested %u ms latency, got %d ms\n", latency, (int)(out.samples * 4 * 1000 / settings->audio.out_rate)); @@ -160,9 +166,11 @@ static ssize_t sdl_audio_write(void *data, const void *buf, size_t size) if (avail == 0) { SDL_UnlockAudio(); +#ifdef HAVE_THREADS slock_lock(sdl->lock); scond_wait(sdl->cond, sdl->lock); slock_unlock(sdl->lock); +#endif } else { @@ -220,8 +228,10 @@ static void sdl_audio_free(void *data) if (sdl) { fifo_free(sdl->buffer); +#ifdef HAVE_THREADS slock_free(sdl->lock); scond_free(sdl->cond); +#endif } free(sdl); } diff --git a/camera/camera_driver.h b/camera/camera_driver.h index 5a767df5a6..bfd6f6bf18 100644 --- a/camera/camera_driver.h +++ b/camera/camera_driver.h @@ -18,8 +18,9 @@ #define __CAMERA_DRIVER__H #include + #include -#include "../libretro.h" +#include #ifdef __cplusplus extern "C" { diff --git a/cheevos.c b/cheevos.c index 0335de628a..672ad41f11 100644 --- a/cheevos.c +++ b/cheevos.c @@ -20,8 +20,10 @@ #include #include #include +#include #include "cheevos.h" +#include "command.h" #include "dynamic.h" #include "libretro.h" #include "system.h" diff --git a/command.c b/command.c index 4259459032..57762309db 100644 --- a/command.c +++ b/command.c @@ -70,6 +70,7 @@ #ifdef HAVE_MENU #include "menu/menu_driver.h" +#include "menu/menu_content.h" #include "menu/menu_display.h" #include "menu/menu_shader.h" #endif @@ -200,40 +201,6 @@ static const struct cmd_map map[] = { { "MENU_B", RETRO_DEVICE_ID_JOYPAD_B }, }; -#if defined(HAVE_NETWORK_CMD) && defined(HAVE_NETPLAY) -static bool command_network_init(command_t *handle, uint16_t port) -{ - int fd; - struct addrinfo *res = NULL; - - RARCH_LOG("Bringing up command interface on port %hu.\n", - (unsigned short)port); - - fd = socket_init((void**)&res, port, NULL, SOCKET_TYPE_DATAGRAM); - - if (fd < 0) - goto error; - - handle->net_fd = fd; - - if (!socket_nonblock(handle->net_fd)) - goto error; - - if (!socket_bind(handle->net_fd, (void*)res)) - { - RARCH_ERR("Failed to bind socket.\n"); - goto error; - } - - freeaddrinfo_retro(res); - return true; - -error: - if (res) - freeaddrinfo_retro(res); - return false; -} - static bool command_get_arg(const char *tok, const char **arg, unsigned *index) { @@ -275,6 +242,75 @@ static bool command_get_arg(const char *tok, return false; } +static void command_parse_sub_msg(command_t *handle, const char *tok) +{ + const char *arg = NULL; + unsigned index = 0; + + if (command_get_arg(tok, &arg, &index)) + { + if (arg) + { + if (!action_map[index].action(arg)) + RARCH_ERR("Command \"%s\" failed.\n", arg); + } + else + handle->state[map[index].id] = true; + } + else + RARCH_WARN("%s \"%s\" %s.\n", + msg_hash_to_str(MSG_UNRECOGNIZED_COMMAND), + tok, + msg_hash_to_str(MSG_RECEIVED)); +} + +static void command_parse_msg(command_t *handle, char *buf) +{ + char *save = NULL; + const char *tok = strtok_r(buf, "\n", &save); + + while (tok) + { + command_parse_sub_msg(handle, tok); + tok = strtok_r(NULL, "\n", &save); + } +} + +#if defined(HAVE_NETWORK_CMD) && defined(HAVE_NETPLAY) +static bool command_network_init(command_t *handle, uint16_t port) +{ + int fd; + struct addrinfo *res = NULL; + + RARCH_LOG("Bringing up command interface on port %hu.\n", + (unsigned short)port); + + fd = socket_init((void**)&res, port, NULL, SOCKET_TYPE_DATAGRAM); + + if (fd < 0) + goto error; + + handle->net_fd = fd; + + if (!socket_nonblock(handle->net_fd)) + goto error; + + if (!socket_bind(handle->net_fd, (void*)res)) + { + RARCH_ERR("Failed to bind socket.\n"); + goto error; + } + + freeaddrinfo_retro(res); + return true; + +error: + if (res) + freeaddrinfo_retro(res); + return false; +} + + static bool send_udp_packet(const char *host, uint16_t port, const char *msg) @@ -389,39 +425,6 @@ bool command_network_send(const char *cmd_) return ret; } -static void command_parse_sub_msg(command_t *handle, const char *tok) -{ - const char *arg = NULL; - unsigned index = 0; - - if (command_get_arg(tok, &arg, &index)) - { - if (arg) - { - if (!action_map[index].action(arg)) - RARCH_ERR("Command \"%s\" failed.\n", arg); - } - else - handle->state[map[index].id] = true; - } - else - RARCH_WARN("%s \"%s\" %s.\n", - msg_hash_to_str(MSG_UNRECOGNIZED_COMMAND), - tok, - msg_hash_to_str(MSG_RECEIVED)); -} - -static void command_parse_msg(command_t *handle, char *buf) -{ - char *save = NULL; - const char *tok = strtok_r(buf, "\n", &save); - - while (tok) - { - command_parse_sub_msg(handle, tok); - tok = strtok_r(NULL, "\n", &save); - } -} static void command_network_poll(command_t *handle) { @@ -869,8 +872,8 @@ static bool command_event_disk_control_append_image(const char *path) * If we actually use append_image, we assume that we * started out in a single disk case, and that this way * of doing it makes the most sense. */ - rarch_ctl(RARCH_CTL_SET_PATHS, (void*)path); - rarch_ctl(RARCH_CTL_FILL_PATHNAMES, NULL); + retroarch_set_pathnames(path); + retroarch_fill_pathnames(); } command_event(CMD_EVENT_AUTOSAVE_INIT, NULL); @@ -1204,7 +1207,7 @@ static bool event_init_content(void) return true; if (!content_does_not_need_content()) - rarch_ctl(RARCH_CTL_FILL_PATHNAMES, NULL); + retroarch_fill_pathnames(); if (!content_init()) return false; @@ -1559,8 +1562,13 @@ static bool command_event_cmd_exec(void *data) } #if defined(HAVE_DYNAMIC) - if (!rarch_ctl(RARCH_CTL_LOAD_CONTENT, NULL)) +#ifdef HAVE_MENU + if (!menu_content_ctl(MENU_CONTENT_CTL_LOAD, NULL)) + { + rarch_ctl(RARCH_CTL_MENU_RUNNING, NULL); return false; + } +#endif #else frontend_driver_set_fork(FRONTEND_FORK_CORE_WITH_ARGS); #endif @@ -1620,15 +1628,16 @@ bool command_event(enum event_command cmd, void *data) #ifdef HAVE_DYNAMIC command_event(CMD_EVENT_LOAD_CORE, NULL); #endif - rarch_ctl(RARCH_CTL_LOAD_CONTENT, NULL); - break; -#ifdef HAVE_FFMPEG + /* fall-through */ case CMD_EVENT_LOAD_CONTENT_FFMPEG: - rarch_ctl(RARCH_CTL_LOAD_CONTENT_FFMPEG, NULL); - break; -#endif case CMD_EVENT_LOAD_CONTENT_IMAGEVIEWER: - rarch_ctl(RARCH_CTL_LOAD_CONTENT_IMAGEVIEWER, NULL); +#ifdef HAVE_MENU + if (!menu_content_ctl(MENU_CONTENT_CTL_LOAD, NULL)) + { + rarch_ctl(RARCH_CTL_MENU_RUNNING, NULL); + return false; + } +#endif break; case CMD_EVENT_LOAD_CONTENT: { @@ -1766,11 +1775,11 @@ bool command_event(enum event_command cmd, void *data) return false; break; case CMD_EVENT_UNLOAD_CORE: - runloop_ctl(RUNLOOP_CTL_PREPARE_DUMMY, NULL); + runloop_prepare_dummy(); command_event(CMD_EVENT_LOAD_CORE_DEINIT, NULL); break; case CMD_EVENT_QUIT: - rarch_ctl(RARCH_CTL_QUIT, NULL); + retroarch_main_quit(); break; case CMD_EVENT_CHEEVOS_HARDCORE_MODE_TOGGLE: #ifdef HAVE_CHEEVOS @@ -2024,20 +2033,17 @@ bool command_event(enum event_command cmd, void *data) driver_ctl(RARCH_DRIVER_CTL_INIT, &flags); } break; - case CMD_EVENT_QUIT_RETROARCH: - rarch_ctl(RARCH_CTL_FORCE_QUIT, NULL); - break; case CMD_EVENT_SHUTDOWN: #if defined(__linux__) && !defined(ANDROID) runloop_msg_queue_push("Shutting down...", 1, 180, true); - rarch_ctl(RARCH_CTL_FORCE_QUIT, NULL); + command_event(CMD_EVENT_QUIT, NULL); system("shutdown -P now"); #endif break; case CMD_EVENT_REBOOT: #if defined(__linux__) && !defined(ANDROID) runloop_msg_queue_push("Rebooting...", 1, 180, true); - rarch_ctl(RARCH_CTL_FORCE_QUIT, NULL); + command_event(CMD_EVENT_QUIT, NULL); system("shutdown -r now"); #endif break; diff --git a/command.h b/command.h index 92dd882916..c1db7db1a9 100644 --- a/command.h +++ b/command.h @@ -44,9 +44,7 @@ enum event_command /* Loads content file. */ CMD_EVENT_LOAD_CONTENT, CMD_EVENT_LOAD_CONTENT_PERSIST, -#ifdef HAVE_FFMPEG CMD_EVENT_LOAD_CONTENT_FFMPEG, -#endif CMD_EVENT_LOAD_CONTENT_IMAGEVIEWER, CMD_EVENT_SET_PER_GAME_RESOLUTION, CMD_EVENT_SET_FRAME_LIMIT, @@ -131,8 +129,6 @@ enum event_command CMD_EVENT_RESET_CONTEXT, /* Restarts RetroArch. */ CMD_EVENT_RESTART_RETROARCH, - /* Force-quit RetroArch. */ - CMD_EVENT_QUIT_RETROARCH, /* Shutdown the OS */ CMD_EVENT_SHUTDOWN, /* Reboot the OS */ diff --git a/content.c b/content.c index 73c0f6ba94..7804333047 100644 --- a/content.c +++ b/content.c @@ -90,6 +90,14 @@ struct sram_block size_t size; }; +typedef struct content_stream +{ + uint32_t a; + const uint8_t *b; + size_t c; + uint32_t crc; +} content_stream_t; + static const struct file_archive_file_backend *stream_backend = NULL; static struct string_list *temporary_content = NULL; static bool _content_is_inited = false; @@ -892,7 +900,7 @@ bool content_load(content_ctx_info_t *info) wrap_args->argc = *rarch_argc_ptr; wrap_args->argv = rarch_argv_ptr; - if (!rarch_ctl(RARCH_CTL_MAIN_INIT, wrap_args)) + if (!retroarch_main_init(wrap_args->argc, wrap_args->argv)) { retval = false; goto error; diff --git a/content.h b/content.h index e02ee8f692..13118f67f9 100644 --- a/content.h +++ b/content.h @@ -36,14 +36,6 @@ typedef struct ram_type int type; } ram_type_t; -typedef struct content_stream -{ - uint32_t a; - const uint8_t *b; - size_t c; - uint32_t crc; -} content_stream_t; - typedef struct content_ctx_info { int argc; /* Argument count. */ diff --git a/core.h b/core.h index 2866e3abcc..d969e82138 100644 --- a/core.h +++ b/core.h @@ -23,9 +23,9 @@ extern "C" { #endif #include +#include #include "core_type.h" -#include "libretro.h" enum { diff --git a/core_impl.c b/core_impl.c index 163ed55396..2c3d365418 100644 --- a/core_impl.c +++ b/core_impl.c @@ -24,9 +24,9 @@ #include #include #include +#include #include "dynamic.h" -#include "libretro.h" #include "core.h" #include "general.h" #include "msg_hash.h" diff --git a/cores/dynamic_dummy.c b/cores/dynamic_dummy.c index ffcdf493a0..53efa0b90a 100644 --- a/cores/dynamic_dummy.c +++ b/cores/dynamic_dummy.c @@ -19,8 +19,9 @@ #include #include +#include + #include "internal_cores.h" -#include "../libretro.h" static uint16_t *frame_buf; diff --git a/cores/internal_cores.h b/cores/internal_cores.h index 60fbb49417..22d25e18aa 100644 --- a/cores/internal_cores.h +++ b/cores/internal_cores.h @@ -19,7 +19,7 @@ #define INTERNAL_CORES_H__ #include -#include "../libretro.h" +#include void libretro_dummy_retro_init(void); diff --git a/cores/libretro-ffmpeg/ffmpeg_core.c b/cores/libretro-ffmpeg/ffmpeg_core.c index 799f54c016..9e56232ae9 100644 --- a/cores/libretro-ffmpeg/ffmpeg_core.c +++ b/cores/libretro-ffmpeg/ffmpeg_core.c @@ -42,7 +42,7 @@ extern "C" { #include #include -#include "libretro.h" +#include #ifdef RARCH_INTERNAL #include "internal_cores.h" #define CORE_PREFIX(s) libretro_ffmpeg_##s diff --git a/cores/libretro-ffmpeg/libretro.h b/cores/libretro-ffmpeg/libretro.h deleted file mode 100644 index 5ed9e5c181..0000000000 --- a/cores/libretro-ffmpeg/libretro.h +++ /dev/null @@ -1 +0,0 @@ -#include "../../libretro.h" diff --git a/cores/libretro-imageviewer/image_core.c b/cores/libretro-imageviewer/image_core.c index 771776e0f5..2a4d168fe0 100644 --- a/cores/libretro-imageviewer/image_core.c +++ b/cores/libretro-imageviewer/image_core.c @@ -22,12 +22,12 @@ #include "../../deps/stb/stb_image.h" +#include + #ifdef RARCH_INTERNAL #include "internal_cores.h" -#include "../../libretro.h" #define IMAGE_CORE_PREFIX(s) libretro_imageviewer_##s #else -#include "libretro.h" #define IMAGE_CORE_PREFIX(s) s #endif diff --git a/cores/libretro-test-gl-ff/libretro_gl_ff_test.c b/cores/libretro-test-gl-ff/libretro_gl_ff_test.c index f9e6d4ce6d..a0f1ee215f 100644 --- a/cores/libretro-test-gl-ff/libretro_gl_ff_test.c +++ b/cores/libretro-test-gl-ff/libretro_gl_ff_test.c @@ -6,7 +6,7 @@ #include -#include "../../libretro.h" +#include #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) static struct retro_hw_render_callback hw_render; diff --git a/cores/libretro-test-gl/libretro_gl_test.c b/cores/libretro-test-gl/libretro_gl_test.c index 139d87ae14..b995d691d9 100644 --- a/cores/libretro-test-gl/libretro_gl_test.c +++ b/cores/libretro-test-gl/libretro_gl_test.c @@ -6,7 +6,7 @@ #include -#include "../../libretro.h" +#include #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) static struct retro_hw_render_callback hw_render; diff --git a/cores/libretro-test/libretro-test.c b/cores/libretro-test/libretro-test.c index bc7e592399..3eccfc83c6 100644 --- a/cores/libretro-test/libretro-test.c +++ b/cores/libretro-test/libretro-test.c @@ -7,7 +7,7 @@ #include -#include "../../libretro.h" +#include static uint32_t *frame_buf; static struct retro_log_callback logging; diff --git a/cores/retropad/retropad.c b/cores/retropad/retropad.c index 608866b57d..6edc342820 100644 --- a/cores/retropad/retropad.c +++ b/cores/retropad/retropad.c @@ -40,7 +40,7 @@ #include -#include "../../libretro.h" +#include #ifndef SOCKET_ERROR #define SOCKET_ERROR -1 diff --git a/deps/spir2cross b/deps/spir2cross deleted file mode 160000 index 0ae2bcc3d0..0000000000 --- a/deps/spir2cross +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0ae2bcc3d0edc60e03180f6080a168f78edc82ca diff --git a/driver.c b/driver.c index 5e6c076363..9bebc2a2a8 100644 --- a/driver.c +++ b/driver.c @@ -17,6 +17,7 @@ #include #include +#include "command.h" #include "general.h" #include "msg_hash.h" #include "system.h" diff --git a/dynamic.c b/dynamic.c index a435df35c0..260e0a9819 100644 --- a/dynamic.c +++ b/dynamic.c @@ -25,6 +25,8 @@ #include #include +#include + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -38,7 +40,6 @@ #include "record/record_driver.h" #include "core.h" #include "performance_counters.h" -#include "performance.h" #include "system.h" #include "gfx/video_context_driver.h" diff --git a/dynamic.h b/dynamic.h index f072f78a7a..4fe1152614 100644 --- a/dynamic.h +++ b/dynamic.h @@ -18,9 +18,9 @@ #define __DYNAMIC_H #include +#include #include "core_type.h" -#include "libretro.h" #ifdef HAVE_CONFIG_H #include "config.h" diff --git a/frontend/drivers/platform_gx.c b/frontend/drivers/platform_gx.c index 6e5d43edee..7478b21148 100644 --- a/frontend/drivers/platform_gx.c +++ b/frontend/drivers/platform_gx.c @@ -426,7 +426,7 @@ static bool frontend_gx_set_fork(enum frontend_fork fork_mode) case FRONTEND_FORK_RESTART: RARCH_LOG("FRONTEND_FORK_RESTART\n"); gx_fork_mode = fork_mode; - rarch_ctl(RARCH_CTL_FORCE_QUIT, NULL); + command_event(CMD_EVENT_QUIT, NULL); break; case FRONTEND_FORK_NONE: default: diff --git a/frontend/drivers/platform_linux.c b/frontend/drivers/platform_linux.c index 634f60c05a..3f48e38a7d 100644 --- a/frontend/drivers/platform_linux.c +++ b/frontend/drivers/platform_linux.c @@ -51,396 +51,10 @@ #include "../../verbosity.h" #include "platform_linux.h" -/* This small data type is used to represent a CPU list / mask, - * as read from sysfs on Linux. - * - * See http://www.kernel.org/doc/Documentation/cputopology.txt - * - * For now, we don't expect more than 32 cores on mobile devices, - * so keep everything simple. - */ -typedef struct -{ - uint32_t mask; -} CpuList; - -static bool cpu_inited_once; -static enum cpu_family g_cpuFamily; -static uint64_t g_cpuFeatures; -static int g_cpuCount; - #ifndef HAVE_DYNAMIC static enum frontend_fork linux_fork_mode = FRONTEND_FORK_NONE; #endif -#ifdef __arm__ -# define DEFAULT_CPU_FAMILY CPU_FAMILY_ARM -#elif defined __i386__ -# define DEFAULT_CPU_FAMILY CPU_FAMILY_X86 -#else -# define DEFAULT_CPU_FAMILY CPU_FAMILY_UNKNOWN -#endif - -#ifdef __i386__ -void x86_cpuid(int func, int flags[4]); -#endif - -#ifdef __ARM_ARCH__ -/* Extract the content of a the first occurrence of a given field in - * the content of /proc/cpuinfo and return it as a heap-allocated - * string that must be freed by the caller. - * - * Return NULL if not found - */ -static char *extract_cpuinfo_field(char* buffer, - ssize_t length, const char* field) -{ - int len; - const char *q; - int fieldlen = strlen(field); - char* bufend = buffer + length; - char* result = NULL; - /* Look for first field occurrence, - * and ensures it starts the line. */ - const char *p = buffer; - - for (;;) - { - p = memmem(p, bufend-p, field, fieldlen); - if (p == NULL) - return result; - - if (p == buffer || p[-1] == '\n') - break; - - p += fieldlen; - } - - /* Skip to the first column followed by a space */ - p += fieldlen; - p = memchr(p, ':', bufend-p); - if (p == NULL || p[1] != ' ') - return result; - - /* Find the end of the line */ - p += 2; - q = memchr(p, '\n', bufend-p); - if (q == NULL) - q = bufend; - - /* Copy the line into a heap-allocated buffer */ - len = q-p; - result = malloc(len+1); - if (result == NULL) - return result; - - memcpy(result, p, len); - result[len] = '\0'; - - return result; -} - -/* Checks that a space-separated list of items - * contains one given 'item'. - * Returns 1 if found, 0 otherwise. - */ -static int has_list_item(const char* list, const char* item) -{ - const char* p = list; - int itemlen = strlen(item); - - if (list == NULL) - return 0; - - while (*p) - { - const char* q; - - /* skip spaces */ - while (*p == ' ' || *p == '\t') - p++; - - /* find end of current list item */ - q = p; - while (*q && *q != ' ' && *q != '\t') - q++; - - if (itemlen == q-p && !memcmp(p, item, itemlen)) - return 1; - - /* skip to next item */ - p = q; - } - return 0; -} -#endif - - -/* Parse an decimal integer starting from 'input', but not going further - * than 'limit'. Return the value into '*result'. - * - * NOTE: Does not skip over leading spaces, or deal with sign characters. - * NOTE: Ignores overflows. - * - * The function returns NULL in case of error (bad format), or the new - * position after the decimal number in case of success (which will always - * be <= 'limit'). - */ -static const char *parse_decimal(const char* input, - const char* limit, int* result) -{ - const char* p = input; - int val = 0; - - while (p < limit) - { - int d = (*p - '0'); - if ((unsigned)d >= 10U) - break; - val = val*10 + d; - p++; - } - if (p == input) - return NULL; - - *result = val; - return p; -} - - -/* Parse a textual list of cpus and store the result inside a CpuList object. - * Input format is the following: - * - comma-separated list of items (no spaces) - * - each item is either a single decimal number (cpu index), or a range made - * of two numbers separated by a single dash (-). Ranges are inclusive. - * - * Examples: 0 - * 2,4-127,128-143 - * 0-1 - */ -static void cpulist_parse(CpuList* list, char **buf, ssize_t length) -{ - const char* p = (const char*)buf; - const char* end = p + length; - - /* NOTE: the input line coming from sysfs typically contains a - * trailing newline, so take care of it in the code below - */ - while (p < end && *p != '\n') - { - int val, start_value, end_value; - /* Find the end of current item, and put it into 'q' */ - const char *q = (const char*)memchr(p, ',', end-p); - - if (!q) - q = end; - - /* Get first value */ - p = parse_decimal(p, q, &start_value); - if (p == NULL) - return; - - end_value = start_value; - - /* If we're not at the end of the item, expect a dash and - * and integer; extract end value. - */ - if (p < q && *p == '-') - { - p = parse_decimal(p+1, q, &end_value); - if (p == NULL) - return; - } - - /* Set bits CPU list bits */ - for (val = start_value; val <= end_value; val++) - { - if ((unsigned)val < 32) - list->mask |= (uint32_t)(1U << val); - } - - /* Jump to next item */ - p = q; - if (p < end) - p++; - } -} - -/* Read a CPU list from one sysfs file */ -static void cpulist_read_from(CpuList* list, const char* filename) -{ - ssize_t length; - char *buf = NULL; - - list->mask = 0; - - if (filestream_read_file(filename, (void**)&buf, &length) != 1) - { - RARCH_ERR("Could not read %s: %s\n", filename, strerror(errno)); - return; - } - - cpulist_parse(list, &buf, length); - if (buf) - free(buf); - buf = NULL; -} - -/* Return the number of cpus present on a given device. - * - * To handle all weird kernel configurations, we need to compute the - * intersection of the 'present' and 'possible' CPU lists and count - * the result. - */ -static int get_cpu_count(void) -{ - CpuList cpus_present[1]; - CpuList cpus_possible[1]; - - cpulist_read_from(cpus_present, "/sys/devices/system/cpu/present"); - cpulist_read_from(cpus_possible, "/sys/devices/system/cpu/possible"); - - /* Compute the intersection of both sets to get the actual number of - * CPU cores that can be used on this device by the kernel. - */ - cpus_present->mask &= cpus_possible->mask; - - return __builtin_popcount(cpus_present->mask); -} - -static void linux_cpu_init(void) -{ - ssize_t length; - void *buf = NULL; - - g_cpuFamily = DEFAULT_CPU_FAMILY; - g_cpuFeatures = 0; - g_cpuCount = 1; - - if (filestream_read_file("/proc/cpuinfo", &buf, &length) != 1) - return; - - /* Count the CPU cores, the value may be 0 for single-core CPUs */ - g_cpuCount = get_cpu_count(); - if (g_cpuCount == 0) - g_cpuCount = 1; - - RARCH_LOG("found cpuCount = %d\n", g_cpuCount); - -#ifdef __ARM_ARCH__ - /* Extract architecture from the "CPU Architecture" field. - * The list is well-known, unlike the the output of - * the 'Processor' field which can vary greatly. - * - * See the definition of the 'proc_arch' array in - * $KERNEL/arch/arm/kernel/setup.c and the 'c_show' function in - * same file. - */ - char* cpu_arch = extract_cpuinfo_field(buf, length, "CPU architecture"); - - if (cpu_arch) - { - char* end; - int has_armv7 = 0; - /* read the initial decimal number, ignore the rest */ - long arch_number = strtol(cpu_arch, &end, 10); - - RARCH_LOG("Found CPU architecture = '%s'\n", cpu_arch); - - /* Here we assume that ARMv8 will be upwards compatible with v7 - * in the future. Unfortunately, there is no 'Features' field to - * indicate that Thumb-2 is supported. - */ - if (end > cpu_arch && arch_number >= 7) - has_armv7 = 1; - - /* Unfortunately, it seems that certain ARMv6-based CPUs - * report an incorrect architecture number of 7! - * - * See http://code.google.com/p/android/issues/detail?id=10812 - * - * We try to correct this by looking at the 'elf_format' - * field reported by the 'Processor' field, which is of the - * form of "(v7l)" for an ARMv7-based CPU, and "(v6l)" for - * an ARMv6-one. - */ - if (has_armv7) - { - char *cpu_proc = extract_cpuinfo_field(buf, length, - "Processor"); - - if (cpu_proc != NULL) - { - RARCH_LOG("found cpu_proc = '%s'\n", cpu_proc); - if (has_list_item(cpu_proc, "(v6l)")) - { - RARCH_ERR("CPU processor and architecture mismatch!!\n"); - has_armv7 = 0; - } - free(cpu_proc); - } - } - - if (has_armv7) - g_cpuFeatures |= CPU_ARM_FEATURE_ARMv7; - - /* The LDREX / STREX instructions are available from ARMv6 */ - if (arch_number >= 6) - g_cpuFeatures |= CPU_ARM_FEATURE_LDREX_STREX; - - free(cpu_arch); - } - - /* Extract the list of CPU features from 'Features' field */ - char* cpu_features = extract_cpuinfo_field(buf, length, "Features"); - - if (cpu_features) - { - RARCH_LOG("found cpu_features = '%s'\n", cpu_features); - - if (has_list_item(cpu_features, "vfpv3")) - g_cpuFeatures |= CPU_ARM_FEATURE_VFPv3; - - else if (has_list_item(cpu_features, "vfpv3d16")) - g_cpuFeatures |= CPU_ARM_FEATURE_VFPv3; - - /* Note: Certain kernels only report NEON but not VFPv3 - * in their features list. However, ARM mandates - * that if NEON is implemented, so must be VFPv3 - * so always set the flag. - */ - if (has_list_item(cpu_features, "neon")) - g_cpuFeatures |= CPU_ARM_FEATURE_NEON | CPU_ARM_FEATURE_VFPv3; - free(cpu_features); - } -#endif /* __ARM_ARCH__ */ - -#ifdef __i386__ - g_cpuFamily = CPU_FAMILY_X86; -#elif defined(_MIPS_ARCH) - g_cpuFamily = CPU_FAMILY_MIPS; -#endif - - if (buf) - free(buf); - buf = NULL; -} - -enum cpu_family linux_get_cpu_platform(void) -{ - return g_cpuFamily; -} - -uint64_t linux_get_cpu_features(void) -{ - return g_cpuFeatures; -} - -int linux_get_cpu_count(void) -{ - return g_cpuCount; -} - int system_property_get(const char *command, const char *args, char *value) { @@ -2165,11 +1779,6 @@ static void frontend_linux_init(void *data) "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;"); #endif - if (!cpu_inited_once) - { - linux_cpu_init(); - cpu_inited_once = true; - } } #ifdef ANDROID @@ -2218,7 +1827,7 @@ static bool frontend_linux_set_fork(enum frontend_fork fork_mode) fill_pathname_application_path(executable_path, sizeof(executable_path)); strlcpy(settings->path.libretro, executable_path, sizeof(settings->path.libretro)); } - rarch_ctl(RARCH_CTL_FORCE_QUIT, NULL); + command_event(CMD_EVENT_QUIT, NULL); break; case FRONTEND_FORK_NONE: default: diff --git a/frontend/drivers/platform_linux.h b/frontend/drivers/platform_linux.h index 9ccdf069b5..345bae2907 100644 --- a/frontend/drivers/platform_linux.h +++ b/frontend/drivers/platform_linux.h @@ -23,31 +23,6 @@ #include -enum cpu_family -{ - CPU_FAMILY_UNKNOWN = 0, - CPU_FAMILY_ARM, - CPU_FAMILY_X86, - CPU_FAMILY_MIPS, - - CPU_FAMILY_MAX /* do not remove */ -}; - -enum -{ - CPU_ARM_FEATURE_ARMv7 = (1 << 0), - CPU_ARM_FEATURE_VFPv3 = (1 << 1), - CPU_ARM_FEATURE_NEON = (1 << 2), - CPU_ARM_FEATURE_LDREX_STREX = (1 << 3) -}; - -enum -{ - CPU_X86_FEATURE_SSSE3 = (1 << 0), - CPU_X86_FEATURE_POPCNT = (1 << 1), - CPU_X86_FEATURE_MOVBE = (1 << 2) -}; - #ifndef MAX_PADS #define MAX_PADS 8 #endif @@ -56,12 +31,6 @@ enum #define MAX_AXIS 10 #endif -enum cpu_family linux_get_cpu_family(void); - -uint64_t linux_get_cpu_features(void); - -int linux_get_cpu_count(void); - #ifdef ANDROID #include #include diff --git a/gfx/common/vulkan_common.c b/gfx/common/vulkan_common.c index 7f232211b1..6a205c6638 100644 --- a/gfx/common/vulkan_common.c +++ b/gfx/common/vulkan_common.c @@ -481,7 +481,9 @@ struct vk_texture vulkan_create_texture(vk_t *vk, submit_info.commandBufferCount = 1; submit_info.pCommandBuffers = &staging; +#ifdef HAVE_THREADS slock_lock(vk->context->queue_lock); +#endif VKFUNC(vkQueueSubmit)(vk->context->queue, 1, &submit_info, VK_NULL_HANDLE); @@ -489,7 +491,9 @@ struct vk_texture vulkan_create_texture(vk_t *vk, * during init, so waiting for GPU to complete transfer * and blocking isn't a big deal. */ VKFUNC(vkQueueWaitIdle)(vk->context->queue); +#ifdef HAVE_THREADS slock_unlock(vk->context->queue_lock); +#endif VKFUNC(vkFreeCommandBuffers)(vk->context->device, vk->staging_pool, 1, &staging); vulkan_destroy_texture( @@ -1423,9 +1427,11 @@ bool vulkan_context_init(gfx_ctx_vulkan_data_t *vk, break; } +#ifdef HAVE_THREADS vk->context.queue_lock = slock_new(); if (!vk->context.queue_lock) return false; +#endif return true; } @@ -1577,7 +1583,9 @@ void vulkan_present(gfx_ctx_vulkan_data_t *vk, unsigned index) present.pWaitSemaphores = &vk->context.swapchain_semaphores[index]; /* Better hope QueuePresent doesn't block D: */ +#ifdef HAVE_THREADS slock_lock(vk->context.queue_lock); +#endif err = VKFUNC(vkQueuePresentKHR)(vk->context.queue, &present); if (err != VK_SUCCESS || result != VK_SUCCESS) @@ -1586,7 +1594,9 @@ void vulkan_present(gfx_ctx_vulkan_data_t *vk, unsigned index) vk->context.invalid_swapchain = true; } +#ifdef HAVE_THREADS slock_unlock(vk->context.queue_lock); +#endif } void vulkan_context_destroy(gfx_ctx_vulkan_data_t *vk, diff --git a/gfx/common/vulkan_common.h b/gfx/common/vulkan_common.h index 6afaa53178..13d0f0b6d9 100644 --- a/gfx/common/vulkan_common.h +++ b/gfx/common/vulkan_common.h @@ -38,13 +38,14 @@ #include #include +#include +#include + #include "../../driver.h" -#include "../../libretro.h" #include "../../general.h" #include "../../retroarch.h" #include "../font_driver.h" #include "../video_context_driver.h" -#include "../../libretro_vulkan.h" #include "../drivers_shader/shader_vulkan.h" typedef struct vulkan_filter_chain vulkan_filter_chain_t; diff --git a/gfx/d3d/render_chain_driver.h b/gfx/d3d/render_chain_driver.h index 498f0000b4..7ccb55be87 100644 --- a/gfx/d3d/render_chain_driver.h +++ b/gfx/d3d/render_chain_driver.h @@ -17,10 +17,11 @@ #ifndef __D3D_RENDER_CHAIN_H #define __D3D_RENDER_CHAIN_H +#include + #include "../video_driver.h" #include "../video_shader_parse.h" #include "../video_state_tracker.h" -#include "../../libretro.h" #include "../../defines/d3d_defines.h" #ifdef __cplusplus diff --git a/gfx/drivers/gl.c b/gfx/drivers/gl.c index f3d240fa52..ae9ea181fc 100644 --- a/gfx/drivers/gl.c +++ b/gfx/drivers/gl.c @@ -31,12 +31,12 @@ #include #include #include +#include #include "../../driver.h" #include "../../record/record_driver.h" #include "../../performance_counters.h" -#include "../../libretro.h" #include "../../general.h" #include "../../retroarch.h" #include "../../verbosity.h" @@ -230,7 +230,8 @@ static bool gl_init_vao(gl_t *gl) #elif !defined(HAVE_OPENGLES2) static bool gl_check_fbo_proc(gl_t *gl) { - if (!gl->core_context && !gl_query_extension(gl, "ARB_framebuffer_object")) + if (!gl->core_context && !gl_query_extension(gl, "ARB_framebuffer_object") + && !gl_query_extension(gl, "EXT_framebuffer_object")) return false; return glGenFramebuffers @@ -2493,7 +2494,7 @@ static void DEBUG_CALLBACK_TYPE gl_debug_cb(GLenum source, GLenum type, const GLchar *message, void *userParam) { const char *src = NULL; - const char **typestr = NULL; + const char *typestr = NULL; gl_t *gl = (gl_t*)userParam; /* Useful for debugger. */ (void)gl; @@ -3786,6 +3787,7 @@ static void video_texture_load_gl( ); } +#ifdef HAVE_THREADS static int video_texture_load_wrap_gl_mipmap(void *data) { uintptr_t id = 0; @@ -3807,6 +3809,7 @@ static int video_texture_load_wrap_gl(void *data) TEXTURE_FILTER_LINEAR, &id); return id; } +#endif static uintptr_t gl_load_texture(void *video_data, void *data, bool threaded, enum texture_filter_type filter_type) diff --git a/gfx/drivers/vg.c b/gfx/drivers/vg.c index 73527ff83c..f7413a50ac 100644 --- a/gfx/drivers/vg.c +++ b/gfx/drivers/vg.c @@ -24,9 +24,9 @@ #include #include #include +#include #include "../video_context_driver.h" -#include "../../libretro.h" #include "../../general.h" #include "../../retroarch.h" #include "../../driver.h" diff --git a/gfx/drivers/vulkan.c b/gfx/drivers/vulkan.c index 1147badfa2..c46ea440e5 100644 --- a/gfx/drivers/vulkan.c +++ b/gfx/drivers/vulkan.c @@ -13,6 +13,20 @@ * If not, see . */ +#include +#include +#include +#include + + +#include +#include +#include +#include +#include +#include +#include + #include "../common/vulkan_common.h" #include "vulkan_shaders/alpha_blend.vert.inc" #include "vulkan_shaders/alpha_blend.frag.inc" @@ -22,23 +36,10 @@ #include "vulkan_shaders/ribbon_simple.vert.inc" #include "vulkan_shaders/ribbon_simple.frag.inc" -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - #include "../../driver.h" #include "../../record/record_driver.h" #include "../../performance_counters.h" -#include "../../libretro.h" #include "../../general.h" #include "../../retroarch.h" @@ -884,13 +885,17 @@ static void vulkan_set_command_buffers(void *handle, uint32_t num_cmd, static void vulkan_lock_queue(void *handle) { vk_t *vk = (vk_t*)handle; +#ifdef HAVE_THREADS slock_lock(vk->context->queue_lock); +#endif } static void vulkan_unlock_queue(void *handle) { vk_t *vk = (vk_t*)handle; +#ifdef HAVE_THREADS slock_unlock(vk->context->queue_lock); +#endif } static void vulkan_init_hw_render(vk_t *vk) @@ -1740,10 +1745,14 @@ static bool vulkan_frame(void *data, const void *frame, retro_perf_start(&queue_submit); +#ifdef HAVE_THREADS slock_lock(vk->context->queue_lock); +#endif VKFUNC(vkQueueSubmit)(vk->context->queue, 1, &submit_info, vk->context->swapchain_fences[frame_index]); +#ifdef HAVE_THREADS slock_unlock(vk->context->queue_lock); +#endif retro_perf_stop(&queue_submit); retro_perf_start(&swapbuffers); @@ -2007,7 +2016,9 @@ static const video_poke_interface_t vulkan_poke_interface = { NULL, NULL, #endif +#ifdef HAVE_MENU vulkan_set_osd_msg, +#endif vulkan_show_mouse, NULL, vulkan_get_current_shader, @@ -2260,9 +2271,13 @@ static bool vulkan_overlay_load(void *data, if (!vk) return false; +#ifdef HAVE_THREADS slock_lock(vk->context->queue_lock); +#endif VKFUNC(vkQueueWaitIdle)(vk->context->queue); +#ifdef HAVE_THREADS slock_unlock(vk->context->queue_lock); +#endif vulkan_overlay_free(vk); vk->overlay.images = (struct vk_texture*) diff --git a/gfx/drivers_context/wayland_ctx.c b/gfx/drivers_context/wayland_ctx.c index 7098916b39..66b7dbbdc9 100644 --- a/gfx/drivers_context/wayland_ctx.c +++ b/gfx/drivers_context/wayland_ctx.c @@ -706,7 +706,7 @@ static void gfx_ctx_wl_destroy(void *data) switch (wl_api) { case GFX_CTX_VULKAN_API: -#ifdef HAVE_VULKAN +#if defined(HAVE_VULKAN) && defined(HAVE_THREADS) if (wl->vk.context.queue_lock) slock_free(wl->vk.context.queue_lock); #endif diff --git a/gfx/drivers_context/x_ctx.c b/gfx/drivers_context/x_ctx.c index 1e6c41101b..1f7aec4f85 100644 --- a/gfx/drivers_context/x_ctx.c +++ b/gfx/drivers_context/x_ctx.c @@ -167,7 +167,7 @@ static void gfx_ctx_x_destroy(void *data) switch (x_api) { case GFX_CTX_VULKAN_API: -#ifdef HAVE_VULKAN +#if defined(HAVE_VULKAN) && defined(HAVE_THREADS) if (x->vk.context.queue_lock) slock_free(x->vk.context.queue_lock); #endif diff --git a/gfx/drivers_context/xegl_ctx.c b/gfx/drivers_context/xegl_ctx.c index 6fa1a2f33b..5d21b9c250 100644 --- a/gfx/drivers_context/xegl_ctx.c +++ b/gfx/drivers_context/xegl_ctx.c @@ -189,16 +189,13 @@ static EGLint *xegl_fill_attribs(xegl_ctx_data_t *xegl, EGLint *attr) #ifdef EGL_KHR_create_context case GFX_CTX_OPENGL_API: { - bool debug = false; unsigned version = xegl->egl.major * 1000 + xegl->egl.minor; bool core = version >= 3001; - struct retro_hw_render_callback *hwr = NULL; - - hwr = video_driver_get_hw_context(); #ifdef GL_DEBUG - debug = true; + bool debug = true; #else - debug = hwr->debug_context; + struct retro_hw_render_callback *hwr = video_driver_get_hw_context(); + bool debug = hwr->debug_context; #endif if (core) diff --git a/gfx/drivers_shader/shader_glsl.c b/gfx/drivers_shader/shader_glsl.c index 38f6b81f1a..e7b3ac687e 100644 --- a/gfx/drivers_shader/shader_glsl.c +++ b/gfx/drivers_shader/shader_glsl.c @@ -1153,7 +1153,10 @@ static void gl_glsl_set_params(void *data, void *shader_data, orig_uniforms[1].enabled = true; for (j = 0; j < 2; j++) - gl_glsl_set_uniform_parameter(glsl, &orig_uniforms[j], NULL); + { + if (orig_uniforms[j].enabled) + gl_glsl_set_uniform_parameter(glsl, &orig_uniforms[j], NULL); + } /* Pass texture coordinates. */ if (uni->orig.tex_coord >= 0) @@ -1204,7 +1207,10 @@ static void gl_glsl_set_params(void *data, void *shader_data, feedback_uniforms[1].enabled = true; for (j = 0; j < 2; j++) - gl_glsl_set_uniform_parameter(glsl, &feedback_uniforms[j], NULL); + { + if (feedback_uniforms[j].enabled) + gl_glsl_set_uniform_parameter(glsl, &feedback_uniforms[j], NULL); + } /* Pass texture coordinates. */ if (uni->feedback.tex_coord >= 0) @@ -1255,7 +1261,10 @@ static void gl_glsl_set_params(void *data, void *shader_data, fbo_tex_params[2].enabled = true; for (j = 0; j < 3; j++) - gl_glsl_set_uniform_parameter(glsl, &fbo_tex_params[j], NULL); + { + if (fbo_tex_params[j].enabled) + gl_glsl_set_uniform_parameter(glsl, &fbo_tex_params[j], NULL); + } if (uni->pass[i].tex_coord >= 0) { @@ -1307,7 +1316,10 @@ static void gl_glsl_set_params(void *data, void *shader_data, prev_tex_params[2].enabled = true; for (j = 0; j < 3; j++) - gl_glsl_set_uniform_parameter(glsl, &prev_tex_params[j], NULL); + { + if (prev_tex_params[j].enabled) + gl_glsl_set_uniform_parameter(glsl, &prev_tex_params[j], NULL); + } /* Pass texture coordinates. */ if (uni->prev[i].tex_coord >= 0) diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 8b380a7dc4..7af875e3e4 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -25,6 +25,7 @@ #endif #include +#include #include "video_thread_wrapper.h" #include "../frontend/frontend_driver.h" @@ -33,7 +34,6 @@ #include "../config.def.h" #include "../retroarch.h" #include "../runloop.h" -#include "../performance.h" #include "../performance_counters.h" #include "../list_special.h" #include "../core.h" diff --git a/gfx/video_driver.h b/gfx/video_driver.h index 450f3b2782..93b5a13c68 100644 --- a/gfx/video_driver.h +++ b/gfx/video_driver.h @@ -22,12 +22,12 @@ #include #include +#include #include "font_driver.h" #include "video_filter.h" #include "video_shader_parse.h" -#include "../libretro.h" #include "../input/input_driver.h" diff --git a/gfx/video_filter.c b/gfx/video_filter.c index fe46697bce..1f59be39ad 100644 --- a/gfx/video_filter.c +++ b/gfx/video_filter.c @@ -19,12 +19,12 @@ #include #include #include +#include #include "../frontend/frontend_driver.h" #include "../config_file_userdata.h" #include "../dynamic.h" #include "../general.h" -#include "../performance.h" #include "../performance_counters.h" #include "../verbosity.h" #include "video_filter.h" diff --git a/gfx/video_filter.h b/gfx/video_filter.h index 7f12f92b55..d8af27ad47 100644 --- a/gfx/video_filter.h +++ b/gfx/video_filter.h @@ -17,9 +17,10 @@ #ifndef RARCH_FILTER_H__ #define RARCH_FILTER_H__ -#include "../libretro.h" #include +#include + #define RARCH_SOFTFILTER_THREADS_AUTO 0 typedef struct rarch_softfilter rarch_softfilter_t; diff --git a/gfx/video_state_python.c b/gfx/video_state_python.c index 2ad9fd1dd7..08c2d0dc67 100644 --- a/gfx/video_state_python.c +++ b/gfx/video_state_python.c @@ -14,18 +14,20 @@ * If not, see . */ -#include #include #include #include +#include + #include #include #include +#include + #include "video_state_python.h" #include "../dynamic.h" -#include "../libretro.h" #include "../core.h" #include "../general.h" #include "../verbosity.h" diff --git a/gfx/video_texture_image.c b/gfx/video_texture_image.c index 349a4332f7..8949781813 100644 --- a/gfx/video_texture_image.c +++ b/gfx/video_texture_image.c @@ -29,8 +29,12 @@ #ifdef HAVE_RPNG #include #endif +#ifdef HAVE_RJPEG #include +#endif +#ifdef HAVE_RTGA #include +#endif #include "../general.h" @@ -264,9 +268,11 @@ bool video_texture_image_load(struct texture_image *out_img, switch (fmt) { case IMAGE_FORMAT_TGA: +#ifdef HAVE_RTGA if (rtga_image_load_shift((uint8_t*)ptr, out_img, a_shift, r_shift, g_shift, b_shift)) goto success; +#endif break; case IMAGE_FORMAT_PNG: #ifdef HAVE_RPNG @@ -276,9 +282,11 @@ bool video_texture_image_load(struct texture_image *out_img, #endif break; case IMAGE_FORMAT_JPEG: +#ifdef HAVE_RJPEG if (rjpeg_image_load((uint8_t*)ptr, out_img, file_len, a_shift, r_shift, g_shift, b_shift)) goto success; +#endif break; default: case IMAGE_FORMAT_NONE: diff --git a/gfx/video_thread_wrapper.c b/gfx/video_thread_wrapper.c index b4b8ca1155..3f7b058e53 100644 --- a/gfx/video_thread_wrapper.c +++ b/gfx/video_thread_wrapper.c @@ -18,12 +18,12 @@ #include #include +#include #include #include "video_thread_wrapper.h" #include "font_driver.h" #include "video_shader_driver.h" -#include "../performance.h" #include "../performance_counters.h" #include "../runloop.h" #include "../verbosity.h" diff --git a/git_version.c b/git_version.c index 12835695e4..3d7a62109e 100644 --- a/git_version.c +++ b/git_version.c @@ -17,5 +17,5 @@ #include "git_version.h" #define STR_(x) #x #define STR(x) STR_(x) -const char rarch_git_version[] = STR(GIT_VERSION); +const char retroarch_git_version[] = STR(GIT_VERSION); diff --git a/git_version.h b/git_version.h index 843d5d1f1c..2217898ee7 100644 --- a/git_version.h +++ b/git_version.h @@ -23,7 +23,7 @@ extern "C" { /* Put this in a separate file so we don't have to rebuilt * retroarch.c every single build. */ -extern const char rarch_git_version[]; +extern const char retroarch_git_version[]; #ifdef __cplusplus } diff --git a/griffin/griffin.c b/griffin/griffin.c index 6fe88a87b8..ba626ee9fe 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -62,7 +62,7 @@ ENCODINGS /*============================================================ PERFORMANCE ============================================================ */ -#include "../performance.c" +#include "../libretro-common/features/features_cpu.c" #include "../performance_counters.c" /*============================================================ @@ -222,7 +222,9 @@ VIDEO IMAGE #include "../gfx/video_texture_image.c" +#ifdef HAVE_RTGA #include "../libretro-common/formats/tga/rtga.c" +#endif #ifdef HAVE_IMAGEVIEWER #include "../cores/libretro-imageviewer/image_core.c" @@ -232,7 +234,9 @@ VIDEO IMAGE #include "../libretro-common/formats/png/rpng.c" #include "../libretro-common/formats/png/rpng_encode.c" #endif +#ifdef HAVE_RJPEG #include "../libretro-common/formats/jpeg/rjpeg.c" +#endif #include "../libretro-common/formats/bmp/rbmp_encode.c" /*============================================================ @@ -430,7 +434,7 @@ INPUT (HID) #include "../input/drivers_hid/null_hid.c" -#if defined(HAVE_LIBUSB) +#if defined(HAVE_LIBUSB) && defined(HAVE_THREADS) #include "../input/drivers_hid/libusb_hid.c" #endif diff --git a/input/common/input_x11_common.c b/input/common/input_x11_common.c index 087bc3a8aa..1e028ad8bb 100644 --- a/input/common/input_x11_common.c +++ b/input/common/input_x11_common.c @@ -14,8 +14,9 @@ * If not, see . */ +#include + #include "input_x11_common.h" -#include "../../libretro.h" static bool x11_mouse_wu; static bool x11_mouse_wd; diff --git a/input/connect/joypad_connection.h b/input/connect/joypad_connection.h index 1e0e270505..1b5c70d768 100644 --- a/input/connect/joypad_connection.h +++ b/input/connect/joypad_connection.h @@ -20,7 +20,7 @@ #include #include -#include "../../libretro.h" +#include typedef void (*send_control_t)(void *data, uint8_t *buf, size_t size); diff --git a/input/drivers/ctr_input.c b/input/drivers/ctr_input.c index b44b1906a2..cc37474e85 100644 --- a/input/drivers/ctr_input.c +++ b/input/drivers/ctr_input.c @@ -15,10 +15,11 @@ #include #include + #include +#include #include "../../driver.h" -#include "../../libretro.h" #include "../../general.h" #include "../input_config.h" #include "../input_joypad_driver.h" diff --git a/input/drivers/gx_input.c b/input/drivers/gx_input.c index c280873b33..6962795464 100644 --- a/input/drivers/gx_input.c +++ b/input/drivers/gx_input.c @@ -23,8 +23,9 @@ #include #include +#include + #include "../../driver.h" -#include "../../libretro.h" #ifndef MAX_PADS #define MAX_PADS 4 diff --git a/input/drivers/ps3_input.c b/input/drivers/ps3_input.c index 58a0325b93..2cfba27289 100644 --- a/input/drivers/ps3_input.c +++ b/input/drivers/ps3_input.c @@ -17,14 +17,14 @@ #include #include -#include - #include +#include +#include + #include "../../defines/ps3_defines.h" #include "../../driver.h" -#include "../../libretro.h" #include "../../general.h" #ifdef HAVE_MOUSE diff --git a/input/drivers/psp_input.c b/input/drivers/psp_input.c index a832cb80e7..d9fcccfc55 100644 --- a/input/drivers/psp_input.c +++ b/input/drivers/psp_input.c @@ -17,8 +17,6 @@ #include #include -#include - #if defined(SN_TARGET_PSP2) #include #include @@ -29,10 +27,12 @@ #include #endif +#include +#include + #include "../../defines/psp_defines.h" #include "../../driver.h" -#include "../../libretro.h" #include "../../general.h" #include "../input_config.h" #ifdef HAVE_KERNEL_PRX diff --git a/input/drivers/sdl_input.c b/input/drivers/sdl_input.c index c07ac18470..3ad5bfa4c8 100644 --- a/input/drivers/sdl_input.c +++ b/input/drivers/sdl_input.c @@ -19,6 +19,7 @@ #include #include +#include #include "../../driver.h" @@ -26,7 +27,6 @@ #include "../../gfx/video_context_driver.h" #include "../../general.h" #include "../../verbosity.h" -#include "../../libretro.h" #include "../input_autodetect.h" #include "../input_config.h" #include "../input_joypad_driver.h" diff --git a/input/drivers/xdk_xinput_input.c b/input/drivers/xdk_xinput_input.c index 7ae411debb..aa7f7d1ae4 100644 --- a/input/drivers/xdk_xinput_input.c +++ b/input/drivers/xdk_xinput_input.c @@ -17,15 +17,15 @@ #include #include -#include - #ifdef _XBOX #include #endif +#include +#include + #include "../../driver.h" #include "../../general.h" -#include "../../libretro.h" #define MAX_PADS 4 diff --git a/input/drivers/xenon360_input.c b/input/drivers/xenon360_input.c index 438d6e1e48..cce53c6c68 100644 --- a/input/drivers/xenon360_input.c +++ b/input/drivers/xenon360_input.c @@ -18,12 +18,13 @@ #include #include -#include "../../driver.h" -#include "../../libretro.h" - #include #include +#include + +#include "../../driver.h" + #define MAX_PADS 4 static uint64_t state[MAX_PADS]; diff --git a/input/input_hid_driver.c b/input/input_hid_driver.c index ce37c24f22..a7b9bdc732 100644 --- a/input/input_hid_driver.c +++ b/input/input_hid_driver.c @@ -29,7 +29,7 @@ static hid_driver_t *hid_drivers[] = { #if defined(__APPLE__) && defined(HAVE_IOHIDMANAGER) &iohidmanager_hid, #endif -#ifdef HAVE_LIBUSB +#if defined(HAVE_LIBUSB) && defined(HAVE_THREADS) &libusb_hid, #endif #ifdef HW_RVL diff --git a/input/input_hid_driver.h b/input/input_hid_driver.h index cc77346afd..2a48c67816 100644 --- a/input/input_hid_driver.h +++ b/input/input_hid_driver.h @@ -24,7 +24,7 @@ extern "C" { #include #include -#include "../libretro.h" +#include typedef struct hid_driver hid_driver_t; diff --git a/input/input_joypad_driver.h b/input/input_joypad_driver.h index 1e1a5edca6..ef6d949dbf 100644 --- a/input/input_joypad_driver.h +++ b/input/input_joypad_driver.h @@ -23,8 +23,7 @@ extern "C" { #include #include - -#include "../libretro.h" +#include typedef struct rarch_joypad_driver input_device_driver_t; diff --git a/input/input_keyboard.h b/input/input_keyboard.h index 50bf53f602..d662ef3042 100644 --- a/input/input_keyboard.h +++ b/input/input_keyboard.h @@ -24,8 +24,7 @@ extern "C" { #include #include - -#include "../libretro.h" +#include enum rarch_input_keyboard_ctl_state { diff --git a/input/input_keymaps.h b/input/input_keymaps.h index 967f444bde..6a99c17ed1 100644 --- a/input/input_keymaps.h +++ b/input/input_keymaps.h @@ -19,7 +19,7 @@ #include -#include "../libretro.h" +#include #ifdef __cplusplus extern "C" { diff --git a/libretro-common/features/features_cpu.c b/libretro-common/features/features_cpu.c new file mode 100644 index 0000000000..3977bbf5b4 --- /dev/null +++ b/libretro-common/features/features_cpu.c @@ -0,0 +1,892 @@ +/* Copyright (C) 2010-2016 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (features_cpu.c). + * --------------------------------------------------------------------------------------- + * + * Permission is hereby granted, free of charge, + * to any person obtaining a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include +#include + +#if defined(_WIN32) +#include +#else +#include +#endif + +#include +#include +#include + +#if defined(_WIN32) && !defined(_XBOX) +#include +#include +#endif + +#if defined(__CELLOS_LV2__) +#ifndef _PPU_INTRINSICS_H +#include +#endif +#elif defined(_XBOX360) +#include +#elif defined(_POSIX_MONOTONIC_CLOCK) || defined(ANDROID) || defined(__QNX__) +/* POSIX_MONOTONIC_CLOCK is not being defined in Android headers despite support being present. */ +#include +#endif + +#if defined(__QNX__) && !defined(CLOCK_MONOTONIC) +#define CLOCK_MONOTONIC 2 +#endif + +#if defined(PSP) +#include +#include +#endif + +#if defined(VITA) +#include +#include +#endif + +#if defined(__PSL1GHT__) +#include +#elif defined(__CELLOS_LV2__) +#include +#endif + +#ifdef GEKKO +#include +#endif + +/* iOS/OSX specific. Lacks clock_gettime(), so implement it. */ +#ifdef __MACH__ +#include + +#ifndef CLOCK_MONOTONIC +#define CLOCK_MONOTONIC 0 +#endif + +#ifndef CLOCK_REALTIME +#define CLOCK_REALTIME 0 +#endif + +static int clock_gettime(int clk_ik, struct timespec *t) +{ + struct timeval now; + int rv = gettimeofday(&now, NULL); + if (rv) + return rv; + t->tv_sec = now.tv_sec; + t->tv_nsec = now.tv_usec * 1000; + return 0; +} +#endif + +#ifdef EMSCRIPTEN +#include +#endif + +#if defined(BSD) || defined(__APPLE__) +#include +#endif + +#include + +/** + * cpu_features_get_perf_counter: + * + * Gets performance counter. + * + * Returns: performance counter. + **/ +retro_perf_tick_t cpu_features_get_perf_counter(void) +{ + retro_perf_tick_t time_ticks = 0; +#if defined(__linux__) || defined(__QNX__) || defined(__MACH__) + struct timespec tv; + if (clock_gettime(CLOCK_MONOTONIC, &tv) == 0) + time_ticks = (retro_perf_tick_t)tv.tv_sec * 1000000000 + + (retro_perf_tick_t)tv.tv_nsec; + +#elif defined(__GNUC__) && defined(__i386__) || defined(__i486__) || defined(__i686__) + __asm__ volatile ("rdtsc" : "=A" (time_ticks)); +#elif defined(__GNUC__) && defined(__x86_64__) + unsigned a, d; + __asm__ volatile ("rdtsc" : "=a" (a), "=d" (d)); + time_ticks = (retro_perf_tick_t)a | ((retro_perf_tick_t)d << 32); +#elif defined(__ARM_ARCH_6__) + __asm__ volatile( "mrc p15, 0, %0, c9, c13, 0" : "=r"(time_ticks) ); +#elif defined(__CELLOS_LV2__) || defined(_XBOX360) || defined(__powerpc__) || defined(__ppc__) || defined(__POWERPC__) + time_ticks = __mftb(); +#elif defined(GEKKO) + time_ticks = gettime(); +#elif defined(PSP) || defined(VITA) + sceRtcGetCurrentTick(&time_ticks); +#elif defined(_3DS) + time_ticks = svcGetSystemTick(); +#elif defined(__mips__) + struct timeval tv; + gettimeofday(&tv,NULL); + time_ticks = (1000000 * tv.tv_sec + tv.tv_usec); +#elif defined(_WIN32) + long tv_sec, tv_usec; + static const unsigned __int64 epoch = 11644473600000000Ui64; + FILETIME file_time; + SYSTEMTIME system_time; + ULARGE_INTEGER ularge; + + GetSystemTime(&system_time); + SystemTimeToFileTime(&system_time, &file_time); + ularge.LowPart = file_time.dwLowDateTime; + ularge.HighPart = file_time.dwHighDateTime; + + tv_sec = (long)((ularge.QuadPart - epoch) / 10000000L); + tv_usec = (long)(system_time.wMilliseconds * 1000); + + time_ticks = (1000000 * tv_sec + tv_usec); +#endif + + return time_ticks; +} + +/** + * cpu_features_get_time_usec: + * + * Gets time in microseconds. + * + * Returns: time in microseconds. + **/ +retro_time_t cpu_features_get_time_usec(void) +{ +#if defined(_WIN32) + static LARGE_INTEGER freq; + LARGE_INTEGER count; + + /* Frequency is guaranteed to not change. */ + if (!freq.QuadPart && !QueryPerformanceFrequency(&freq)) + return 0; + + if (!QueryPerformanceCounter(&count)) + return 0; + return count.QuadPart * 1000000 / freq.QuadPart; +#elif defined(__CELLOS_LV2__) + return sys_time_get_system_time(); +#elif defined(GEKKO) + return ticks_to_microsecs(gettime()); +#elif defined(_POSIX_MONOTONIC_CLOCK) || defined(__QNX__) || defined(ANDROID) || defined(__MACH__) + struct timespec tv = {0}; + if (clock_gettime(CLOCK_MONOTONIC, &tv) < 0) + return 0; + return tv.tv_sec * INT64_C(1000000) + (tv.tv_nsec + 500) / 1000; +#elif defined(EMSCRIPTEN) + return emscripten_get_now() * 1000; +#elif defined(__mips__) + struct timeval tv; + gettimeofday(&tv,NULL); + return (1000000 * tv.tv_sec + tv.tv_usec); +#elif defined(_3DS) + return osGetTime() * 1000; +#elif defined(VITA) + return sceKernelGetProcessTimeWide(); +#else +#error "Your platform does not have a timer function implemented in cpu_features_get_time_usec(). Cannot continue." +#endif +} + +#if defined(__x86_64__) || defined(__i386__) || defined(__i486__) || defined(__i686__) +#define CPU_X86 +#endif + +#if defined(_MSC_VER) && !defined(_XBOX) +#include +#endif + +#if defined(CPU_X86) && !defined(__MACH__) +void x86_cpuid(int func, int flags[4]) +{ + /* On Android, we compile RetroArch with PIC, and we + * are not allowed to clobber the ebx register. */ +#ifdef __x86_64__ +#define REG_b "rbx" +#define REG_S "rsi" +#else +#define REG_b "ebx" +#define REG_S "esi" +#endif + +#if defined(__GNUC__) + __asm__ volatile ( + "mov %%" REG_b ", %%" REG_S "\n" + "cpuid\n" + "xchg %%" REG_b ", %%" REG_S "\n" + : "=a"(flags[0]), "=S"(flags[1]), "=c"(flags[2]), "=d"(flags[3]) + : "a"(func)); +#elif defined(_MSC_VER) + __cpuid(flags, func); +#else + printf("Unknown compiler. Cannot check CPUID with inline assembly.\n"); + memset(flags, 0, 4 * sizeof(int)); +#endif +} + +/* Only runs on i686 and above. Needs to be conditionally run. */ +static uint64_t xgetbv_x86(uint32_t idx) +{ +#if defined(__GNUC__) + uint32_t eax, edx; + __asm__ volatile ( + /* Older GCC versions (Apple's GCC for example) do + * not understand xgetbv instruction. + * Stamp out the machine code directly. + */ + ".byte 0x0f, 0x01, 0xd0\n" + : "=a"(eax), "=d"(edx) : "c"(idx)); + return ((uint64_t)edx << 32) | eax; +#elif _MSC_FULL_VER >= 160040219 + /* Intrinsic only works on 2010 SP1 and above. */ + return _xgetbv(idx); +#else + printf("Unknown compiler. Cannot check xgetbv bits.\n"); + return 0; +#endif +} +#endif + +#if defined(__ARM_NEON__) +static void arm_enable_runfast_mode(void) +{ + /* RunFast mode. Enables flush-to-zero and some + * floating point optimizations. */ + static const unsigned x = 0x04086060; + static const unsigned y = 0x03000000; + int r; + __asm__ volatile( + "fmrx %0, fpscr \n\t" /* r0 = FPSCR */ + "and %0, %0, %1 \n\t" /* r0 = r0 & 0x04086060 */ + "orr %0, %0, %2 \n\t" /* r0 = r0 | 0x03000000 */ + "fmxr fpscr, %0 \n\t" /* FPSCR = r0 */ + : "=r"(r) + : "r"(x), "r"(y) + ); +} +#endif + +#if defined(__linux__) && !defined(CPU_X86) + +/* Extract the content of a the first occurrence of a given field in + * the content of /proc/cpuinfo and return it as a heap-allocated + * string that must be freed by the caller. + * + * Return NULL if not found + */ +static char *extract_cpuinfo_field(char* buffer, + ssize_t length, const char* field) +{ + int len; + const char *q; + int fieldlen = strlen(field); + char* bufend = buffer + length; + char* result = NULL; + /* Look for first field occurrence, + * and ensures it starts the line. */ + const char *p = buffer; + + for (;;) + { + p = memmem(p, bufend-p, field, fieldlen); + if (p == NULL) + return result; + + if (p == buffer || p[-1] == '\n') + break; + + p += fieldlen; + } + + /* Skip to the first column followed by a space */ + p += fieldlen; + p = memchr(p, ':', bufend-p); + if (p == NULL || p[1] != ' ') + return result; + + /* Find the end of the line */ + p += 2; + q = memchr(p, '\n', bufend-p); + if (q == NULL) + q = bufend; + + /* Copy the line into a heap-allocated buffer */ + len = q-p; + result = malloc(len+1); + if (result == NULL) + return result; + + memcpy(result, p, len); + result[len] = '\0'; + + return result; +} + +/* Checks that a space-separated list of items + * contains one given 'item'. + * Returns 1 if found, 0 otherwise. + */ +static int has_list_item(const char* list, const char* item) +{ + const char* p = list; + int itemlen = strlen(item); + + if (list == NULL) + return 0; + + while (*p) + { + const char* q; + + /* skip spaces */ + while (*p == ' ' || *p == '\t') + p++; + + /* find end of current list item */ + q = p; + while (*q && *q != ' ' && *q != '\t') + q++; + + if (itemlen == q-p && !memcmp(p, item, itemlen)) + return 1; + + /* skip to next item */ + p = q; + } + return 0; +} + +typedef struct +{ + uint32_t mask; +} CpuList; + + +#if !defined(_SC_NPROCESSORS_ONLN) +/* Parse an decimal integer starting from 'input', but not going further + * than 'limit'. Return the value into '*result'. + * + * NOTE: Does not skip over leading spaces, or deal with sign characters. + * NOTE: Ignores overflows. + * + * The function returns NULL in case of error (bad format), or the new + * position after the decimal number in case of success (which will always + * be <= 'limit'). + */ +static const char *parse_decimal(const char* input, + const char* limit, int* result) +{ + const char* p = input; + int val = 0; + + while (p < limit) + { + int d = (*p - '0'); + if ((unsigned)d >= 10U) + break; + val = val*10 + d; + p++; + } + if (p == input) + return NULL; + + *result = val; + return p; +} + +/* Parse a textual list of cpus and store the result inside a CpuList object. + * Input format is the following: + * - comma-separated list of items (no spaces) + * - each item is either a single decimal number (cpu index), or a range made + * of two numbers separated by a single dash (-). Ranges are inclusive. + * + * Examples: 0 + * 2,4-127,128-143 + * 0-1 + */ +static void cpulist_parse(CpuList* list, char **buf, ssize_t length) +{ + const char* p = (const char*)buf; + const char* end = p + length; + + /* NOTE: the input line coming from sysfs typically contains a + * trailing newline, so take care of it in the code below + */ + while (p < end && *p != '\n') + { + int val, start_value, end_value; + /* Find the end of current item, and put it into 'q' */ + const char *q = (const char*)memchr(p, ',', end-p); + + if (!q) + q = end; + + /* Get first value */ + p = parse_decimal(p, q, &start_value); + if (p == NULL) + return; + + end_value = start_value; + + /* If we're not at the end of the item, expect a dash and + * and integer; extract end value. + */ + if (p < q && *p == '-') + { + p = parse_decimal(p+1, q, &end_value); + if (p == NULL) + return; + } + + /* Set bits CPU list bits */ + for (val = start_value; val <= end_value; val++) + { + if ((unsigned)val < 32) + list->mask |= (uint32_t)(1U << val); + } + + /* Jump to next item */ + p = q; + if (p < end) + p++; + } +} + +/* Read a CPU list from one sysfs file */ +static void cpulist_read_from(CpuList* list, const char* filename) +{ + ssize_t length; + char *buf = NULL; + + list->mask = 0; + + if (filestream_read_file(filename, (void**)&buf, &length) != 1) + return; + + cpulist_parse(list, &buf, length); + if (buf) + free(buf); + buf = NULL; +} +#endif + +#endif + +/** + * cpu_features_get_core_amount: + * + * Gets the amount of available CPU cores. + * + * Returns: amount of CPU cores available. + **/ +unsigned cpu_features_get_core_amount(void) +{ +#if defined(_WIN32) && !defined(_XBOX) + /* Win32 */ + SYSTEM_INFO sysinfo; + GetSystemInfo(&sysinfo); + return sysinfo.dwNumberOfProcessors; +#elif defined(GEKKO) + return 1; +#elif defined(PSP) + return 1; +#elif defined(VITA) + return 4; +#elif defined(_3DS) + return 1; +#elif defined(_SC_NPROCESSORS_ONLN) + /* Linux, most UNIX-likes. */ + long ret = sysconf(_SC_NPROCESSORS_ONLN); + if (ret <= 0) + return (unsigned)1; + return ret; +#elif defined(BSD) || defined(__APPLE__) + /* BSD */ + /* Copypasta from stackoverflow, dunno if it works. */ + int num_cpu = 0; + int mib[4]; + size_t len = sizeof(num_cpu); + + mib[0] = CTL_HW; + mib[1] = HW_AVAILCPU; + sysctl(mib, 2, &num_cpu, &len, NULL, 0); + if (num_cpu < 1) + { + mib[1] = HW_NCPU; + sysctl(mib, 2, &num_cpu, &len, NULL, 0); + if (num_cpu < 1) + num_cpu = 1; + } + return num_cpu; +#elif defined(__linux__) + CpuList cpus_present[1]; + CpuList cpus_possible[1]; + int amount = 0; + + cpulist_read_from(cpus_present, "/sys/devices/system/cpu/present"); + cpulist_read_from(cpus_possible, "/sys/devices/system/cpu/possible"); + + /* Compute the intersection of both sets to get the actual number of + * CPU cores that can be used on this device by the kernel. + */ + cpus_present->mask &= cpus_possible->mask; + amount = __builtin_popcount(cpus_present->mask); + + if (amount == 0) + return 1; + return amount; +#elif defined(_XBOX360) + return 3; +#else + /* No idea, assume single core. */ + return 1; +#endif +} + +/* According to http://en.wikipedia.org/wiki/CPUID */ +#define VENDOR_INTEL_b 0x756e6547 +#define VENDOR_INTEL_c 0x6c65746e +#define VENDOR_INTEL_d 0x49656e69 + +/** + * cpu_features_get: + * + * Gets CPU features.. + * + * Returns: bitmask of all CPU features available. + **/ +uint64_t cpu_features_get(void) +{ + int flags[4]; + int vendor_shuffle[3]; + char vendor[13] = {0}; + size_t len = 0; + uint64_t cpu_flags = 0; + uint64_t cpu = 0; + unsigned max_flag = 0; +#if defined(CPU_X86) && !defined(__MACH__) + int vendor_is_intel = 0; + const int avx_flags = (1 << 27) | (1 << 28); +#endif + + char buf[sizeof(" MMX MMXEXT SSE SSE2 SSE3 SSSE3 SS4 SSE4.2 AES AVX AVX2 NEON VMX VMX128 VFPU PS")]; + + memset(buf, 0, sizeof(buf)); + + (void)len; + (void)cpu_flags; + (void)flags; + (void)max_flag; + (void)vendor; + (void)vendor_shuffle; + +#if defined(__MACH__) + len = sizeof(size_t); + if (sysctlbyname("hw.optional.mmx", NULL, &len, NULL, 0) == 0) + { + cpu |= RETRO_SIMD_MMX; + cpu |= RETRO_SIMD_MMXEXT; + } + + len = sizeof(size_t); + if (sysctlbyname("hw.optional.sse", NULL, &len, NULL, 0) == 0) + cpu |= RETRO_SIMD_SSE; + + len = sizeof(size_t); + if (sysctlbyname("hw.optional.sse2", NULL, &len, NULL, 0) == 0) + cpu |= RETRO_SIMD_SSE2; + + len = sizeof(size_t); + if (sysctlbyname("hw.optional.sse3", NULL, &len, NULL, 0) == 0) + cpu |= RETRO_SIMD_SSE3; + + len = sizeof(size_t); + if (sysctlbyname("hw.optional.supplementalsse3", NULL, &len, NULL, 0) == 0) + cpu |= RETRO_SIMD_SSSE3; + + len = sizeof(size_t); + if (sysctlbyname("hw.optional.sse4_1", NULL, &len, NULL, 0) == 0) + cpu |= RETRO_SIMD_SSE4; + + len = sizeof(size_t); + if (sysctlbyname("hw.optional.sse4_2", NULL, &len, NULL, 0) == 0) + cpu |= RETRO_SIMD_SSE42; + + len = sizeof(size_t); + if (sysctlbyname("hw.optional.aes", NULL, &len, NULL, 0) == 0) + cpu |= RETRO_SIMD_AES; + + len = sizeof(size_t); + if (sysctlbyname("hw.optional.avx1_0", NULL, &len, NULL, 0) == 0) + cpu |= RETRO_SIMD_AVX; + + len = sizeof(size_t); + if (sysctlbyname("hw.optional.avx2_0", NULL, &len, NULL, 0) == 0) + cpu |= RETRO_SIMD_AVX2; + + len = sizeof(size_t); + if (sysctlbyname("hw.optional.altivec", NULL, &len, NULL, 0) == 0) + cpu |= RETRO_SIMD_VMX; + + len = sizeof(size_t); + if (sysctlbyname("hw.optional.neon", NULL, &len, NULL, 0) == 0) + cpu |= RETRO_SIMD_NEON; + +#elif defined(CPU_X86) + (void)avx_flags; + + x86_cpuid(0, flags); + vendor_shuffle[0] = flags[1]; + vendor_shuffle[1] = flags[3]; + vendor_shuffle[2] = flags[2]; + memcpy(vendor, vendor_shuffle, sizeof(vendor_shuffle)); + + printf("[CPUID]: Vendor: %s\n", vendor); + + vendor_is_intel = ( + flags[1] == VENDOR_INTEL_b && + flags[2] == VENDOR_INTEL_c && + flags[3] == VENDOR_INTEL_d); + + max_flag = flags[0]; + if (max_flag < 1) /* Does CPUID not support func = 1? (unlikely ...) */ + return 0; + + x86_cpuid(1, flags); + + if (flags[3] & (1 << 23)) + cpu |= RETRO_SIMD_MMX; + + if (flags[3] & (1 << 25)) + { + /* SSE also implies MMXEXT (according to FFmpeg source). */ + cpu |= RETRO_SIMD_SSE; + cpu |= RETRO_SIMD_MMXEXT; + } + + + if (flags[3] & (1 << 26)) + cpu |= RETRO_SIMD_SSE2; + + if (flags[2] & (1 << 0)) + cpu |= RETRO_SIMD_SSE3; + + if (flags[2] & (1 << 9)) + cpu |= RETRO_SIMD_SSSE3; + + if (flags[2] & (1 << 19)) + cpu |= RETRO_SIMD_SSE4; + + if (flags[2] & (1 << 20)) + cpu |= RETRO_SIMD_SSE42; + + if ((flags[2] & (1 << 23))) + cpu |= RETRO_SIMD_POPCNT; + + if (vendor_is_intel && (flags[2] & (1 << 22))) + cpu |= RETRO_SIMD_MOVBE; + + if (flags[2] & (1 << 25)) + cpu |= RETRO_SIMD_AES; + + + /* Must only perform xgetbv check if we have + * AVX CPU support (guaranteed to have at least i686). */ + if (((flags[2] & avx_flags) == avx_flags) + && ((xgetbv_x86(0) & 0x6) == 0x6)) + cpu |= RETRO_SIMD_AVX; + + if (max_flag >= 7) + { + x86_cpuid(7, flags); + if (flags[1] & (1 << 5)) + cpu |= RETRO_SIMD_AVX2; + } + + x86_cpuid(0x80000000, flags); + max_flag = flags[0]; + if (max_flag >= 0x80000001u) + { + x86_cpuid(0x80000001, flags); + if (flags[3] & (1 << 23)) + cpu |= RETRO_SIMD_MMX; + if (flags[3] & (1 << 22)) + cpu |= RETRO_SIMD_MMXEXT; + } +#elif defined(__linux__) + + static bool cpu_inited_once = false; + static uint64_t g_cpuFeatures = 0; + + enum + { + CPU_ARM_FEATURE_ARMv7 = (1 << 0), + CPU_ARM_FEATURE_VFPv3 = (1 << 1), + CPU_ARM_FEATURE_NEON = (1 << 2), + CPU_ARM_FEATURE_LDREX_STREX = (1 << 3) + }; + + if (!cpu_inited_once) + { + ssize_t length; + void *buf = NULL; + + if (filestream_read_file("/proc/cpuinfo", &buf, &length) == 1) + { + char* cpu_features = NULL; + /* Extract architecture from the "CPU Architecture" field. + * The list is well-known, unlike the the output of + * the 'Processor' field which can vary greatly. + * + * See the definition of the 'proc_arch' array in + * $KERNEL/arch/arm/kernel/setup.c and the 'c_show' function in + * same file. + */ + char* cpu_arch = extract_cpuinfo_field(buf, length, "CPU architecture"); + + if (cpu_arch) + { + char* end = NULL; + int has_armv7 = 0; + /* Read the initial decimal number, ignore the rest */ + long arch_number = strtol(cpu_arch, &end, 10); + + /* Here we assume that ARMv8 will be upwards compatible with v7 + * in the future. Unfortunately, there is no 'Features' field to + * indicate that Thumb-2 is supported. + */ + if (end > cpu_arch && arch_number >= 7) + has_armv7 = 1; + + /* Unfortunately, it seems that certain ARMv6-based CPUs + * report an incorrect architecture number of 7! + * + * See http://code.google.com/p/android/issues/detail?id=10812 + * + * We try to correct this by looking at the 'elf_format' + * field reported by the 'Processor' field, which is of the + * form of "(v7l)" for an ARMv7-based CPU, and "(v6l)" for + * an ARMv6-one. + */ + if (has_armv7) + { + char *cpu_proc = extract_cpuinfo_field(buf, length, + "Processor"); + + if (cpu_proc) + { + /* CPU processor and architecture mismatch. */ + if (has_list_item(cpu_proc, "(v6l)")) + has_armv7 = 0; + free(cpu_proc); + } + } + + if (has_armv7) + g_cpuFeatures |= CPU_ARM_FEATURE_ARMv7; + + /* The LDREX / STREX instructions are available from ARMv6 */ + if (arch_number >= 6) + g_cpuFeatures |= CPU_ARM_FEATURE_LDREX_STREX; + + } + + /* Extract the list of CPU features from 'Features' field */ + cpu_features = extract_cpuinfo_field(buf, length, "Features"); + + if (cpu_features) + { + if (has_list_item(cpu_features, "vfpv3")) + g_cpuFeatures |= CPU_ARM_FEATURE_VFPv3; + else if (has_list_item(cpu_features, "vfpv3d16")) + g_cpuFeatures |= CPU_ARM_FEATURE_VFPv3; + + /* Note: Certain kernels only report NEON but not VFPv3 + * in their features list. However, ARM mandates + * that if NEON is implemented, so must be VFPv3 + * so always set the flag. + */ + if (has_list_item(cpu_features, "neon")) + g_cpuFeatures |= CPU_ARM_FEATURE_NEON | CPU_ARM_FEATURE_VFPv3; + } + + if (cpu_features) + free(cpu_features); + if (cpu_arch) + free(cpu_arch); + if (buf) + free(buf); + cpu_features = NULL; + cpu_arch = NULL; + buf = NULL; + } + cpu_inited_once = true; + } + + cpu_flags = g_cpuFeatures; + + if (cpu_flags & CPU_ARM_FEATURE_NEON) + { + cpu |= RETRO_SIMD_NEON; +#ifdef __ARM_NEON__ + arm_enable_runfast_mode(); +#endif + } + + if (cpu_flags & CPU_ARM_FEATURE_VFPv3) + cpu |= RETRO_SIMD_VFPV3; + +#elif defined(__ARM_NEON__) + cpu |= RETRO_SIMD_NEON; + arm_enable_runfast_mode(); +#elif defined(__ALTIVEC__) + cpu |= RETRO_SIMD_VMX; +#elif defined(XBOX360) + cpu |= RETRO_SIMD_VMX128; +#elif defined(PSP) + cpu |= RETRO_SIMD_VFPU; +#elif defined(GEKKO) + cpu |= RETRO_SIMD_PS; +#endif + + if (cpu & RETRO_SIMD_MMX) strlcat(buf, " MMX", sizeof(buf)); + if (cpu & RETRO_SIMD_MMXEXT) strlcat(buf, " MMXEXT", sizeof(buf)); + if (cpu & RETRO_SIMD_SSE) strlcat(buf, " SSE", sizeof(buf)); + if (cpu & RETRO_SIMD_SSE2) strlcat(buf, " SSE2", sizeof(buf)); + if (cpu & RETRO_SIMD_SSE3) strlcat(buf, " SSE3", sizeof(buf)); + if (cpu & RETRO_SIMD_SSSE3) strlcat(buf, " SSSE3", sizeof(buf)); + if (cpu & RETRO_SIMD_SSE4) strlcat(buf, " SSE4", sizeof(buf)); + if (cpu & RETRO_SIMD_SSE42) strlcat(buf, " SSE4.2", sizeof(buf)); + if (cpu & RETRO_SIMD_AES) strlcat(buf, " AES", sizeof(buf)); + if (cpu & RETRO_SIMD_AVX) strlcat(buf, " AVX", sizeof(buf)); + if (cpu & RETRO_SIMD_AVX2) strlcat(buf, " AVX2", sizeof(buf)); + if (cpu & RETRO_SIMD_NEON) strlcat(buf, " NEON", sizeof(buf)); + if (cpu & RETRO_SIMD_VFPV3) strlcat(buf, " VFPv3", sizeof(buf)); + if (cpu & RETRO_SIMD_VFPV4) strlcat(buf, " VFPv4", sizeof(buf)); + if (cpu & RETRO_SIMD_VMX) strlcat(buf, " VMX", sizeof(buf)); + if (cpu & RETRO_SIMD_VMX128) strlcat(buf, " VMX128", sizeof(buf)); + if (cpu & RETRO_SIMD_VFPU) strlcat(buf, " VFPU", sizeof(buf)); + if (cpu & RETRO_SIMD_PS) strlcat(buf, " PS", sizeof(buf)); + + return cpu; +} diff --git a/libretro-common/file/retro_dirent.c b/libretro-common/file/retro_dirent.c index bdb50094a9..15046be14c 100644 --- a/libretro-common/file/retro_dirent.c +++ b/libretro-common/file/retro_dirent.c @@ -158,7 +158,7 @@ const char *retro_dirent_get_name(struct RDIR *rdir) * Returns: true if directory listing entry is * a directory, false if not. */ -bool retro_dirent_is_dir(struct RDIR *rdir) +bool retro_dirent_is_dir(struct RDIR *rdir, const char *path) { #if defined(_WIN32) const WIN32_FIND_DATA *entry = (const WIN32_FIND_DATA*)&rdir->entry; @@ -174,18 +174,15 @@ bool retro_dirent_is_dir(struct RDIR *rdir) CellFsDirent *entry = (CellFsDirent*)&rdir->entry; return (entry->d_type == CELL_FS_TYPE_DIRECTORY); #elif defined(DT_DIR) - const char *path = NULL; const struct dirent *entry = (const struct dirent*)rdir->entry; if (entry->d_type == DT_DIR) return true; /* This can happen on certain file systems. */ - path = retro_dirent_get_name(rdir); if (entry->d_type == DT_UNKNOWN || entry->d_type == DT_LNK) return path_is_directory(path); return false; #else /* dirent struct doesn't have d_type, do it the slow way ... */ - const char *path = retro_dirent_get_name(rdir); return path_is_directory(path); #endif } diff --git a/libretro-common/formats/jpeg/rjpeg.c b/libretro-common/formats/jpeg/rjpeg.c index 4d43a66c76..a9ca0b753f 100644 --- a/libretro-common/formats/jpeg/rjpeg.c +++ b/libretro-common/formats/jpeg/rjpeg.c @@ -1,3 +1,25 @@ +/* Copyright (C) 2010-2016 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (rjpeg.c). + * --------------------------------------------------------------------------------------- + * + * Permission is hereby granted, free of charge, + * to any person obtaining a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + /* Modified version of stb_image's JPEG sources. */ @@ -11,6 +33,7 @@ #include #include #include +#include enum { @@ -88,51 +111,19 @@ typedef struct #include #ifdef _MSC_VER - -#if _MSC_VER >= 1400 /* not VC6 */ -#include /* __cpuid */ -static int rjpeg__cpuid3(void) -{ - int info[4]; - __cpuid(info,1); - return info[3]; -} -#else -static int rjpeg__cpuid3(void) -{ - int res; - __asm { - mov eax,1 - cpuid - mov res,edx - } - return res; -} -#endif - #define RJPEG_SIMD_ALIGN(type, name) __declspec(align(16)) type name - -static int rjpeg__sse2_available(void) -{ - int info3 = rjpeg__cpuid3(); - return ((info3 >> 26) & 1) != 0; -} -#else /* assume GCC-style if not VC++ */ -#define RJPEG_SIMD_ALIGN(type, name) type name __attribute__((aligned(16))) - -static int rjpeg__sse2_available(void) -{ -#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 408 /* GCC 4.8 or later */ - /* GCC 4.8+ has a nice way to do this */ - return __builtin_cpu_supports("sse2"); #else - /* portable way to do this, preferably without using GCC inline ASM? - * just bail for now. */ +#define RJPEG_SIMD_ALIGN(type, name) type name __attribute__((aligned(16))) +#endif + +static int rjpeg__sse2_available(void) +{ + uint64_t mask = cpu_features_get(); + if (mask & RETRO_SIMD_SSE2) + return 1; return 0; -#endif } #endif -#endif /* ARM NEON */ #if defined(RJPEG_NO_SIMD) && defined(RJPEG_NEON) @@ -2453,7 +2444,9 @@ bool rjpeg_image_load(uint8_t *_buf, void *data, size_t size, unsigned a_shift, unsigned r_shift, unsigned g_shift, unsigned b_shift) { - int x, y, comp; + int comp; + int x = 0; + int y = 0; struct texture_image *out_img = (struct texture_image*)data; out_img->pixels = (uint32_t*)rjpeg_load_from_memory(_buf, size, &x, &y, &comp, 4); diff --git a/libretro-common/glsym/glsym_es3.c b/libretro-common/glsym/glsym_es3.c new file mode 100644 index 0000000000..a8c0657824 --- /dev/null +++ b/libretro-common/glsym/glsym_es3.c @@ -0,0 +1,10 @@ +#include "glsym.h" +#include +#define SYM(x) { "gl" #x, &(gl##x) } +const struct rglgen_sym_map rglgen_symbol_map[] = { + + + { NULL, NULL }, +}; + + diff --git a/libretro-common/include/features/features_cpu.h b/libretro-common/include/features/features_cpu.h new file mode 100644 index 0000000000..019c7f76a4 --- /dev/null +++ b/libretro-common/include/features/features_cpu.h @@ -0,0 +1,72 @@ +/* Copyright (C) 2010-2016 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (features_cpu.h). + * --------------------------------------------------------------------------------------- + * + * Permission is hereby granted, free of charge, + * to any person obtaining a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef _LIBRETRO_SDK_CPU_INFO_H +#define _LIBRETRO_SDK_CPU_INFO_H + +#include + +#include + +#include + +RETRO_BEGIN_DECLS + +/** + * cpu_features_get_perf_counter: + * + * Gets performance counter. + * + * Returns: performance counter. + **/ +retro_perf_tick_t cpu_features_get_perf_counter(void); + +/** + * cpu_features_get_time_usec: + * + * Gets time in microseconds. * + * Returns: time in microseconds. + **/ +retro_time_t cpu_features_get_time_usec(void); + +/** + * cpu_features_get: + * + * Gets CPU features.. + * + * Returns: bitmask of all CPU features available. + **/ +uint64_t cpu_features_get(void); + +/** + * cpu_features_get_core_amount: + * + * Gets the amount of available CPU cores. + * + * Returns: amount of CPU cores available. + **/ +unsigned cpu_features_get_core_amount(void); + +RETRO_END_DECLS + +#endif + diff --git a/libretro-common/include/formats/image.h b/libretro-common/include/formats/image.h index 1f96b81efd..3c98761b3e 100644 --- a/libretro-common/include/formats/image.h +++ b/libretro-common/include/formats/image.h @@ -1,6 +1,6 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2010-2014 - Hans-Kristian Arntzen - * Copyright (C) 2011-2015 - Daniel De Matteis + * Copyright (C) 2011-2016 - 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- diff --git a/libretro-common/include/formats/jsonsax.h b/libretro-common/include/formats/jsonsax.h index 76860fe5f5..86d6d6b207 100644 --- a/libretro-common/include/formats/jsonsax.h +++ b/libretro-common/include/formats/jsonsax.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2010-2015 The RetroArch team +/* Copyright (C) 2010-2016 The RetroArch team * * --------------------------------------------------------------------------------------- * The following license statement only applies to this file (jsonsax.h). diff --git a/libretro-common/include/formats/rjpeg.h b/libretro-common/include/formats/rjpeg.h index 539fd058df..81f61b92af 100644 --- a/libretro-common/include/formats/rjpeg.h +++ b/libretro-common/include/formats/rjpeg.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2010-2015 The RetroArch team +/* Copyright (C) 2010-2016 The RetroArch team * * --------------------------------------------------------------------------------------- * The following license statement only applies to this file (rjpeg.h). diff --git a/libretro-common/include/formats/rxml.h b/libretro-common/include/formats/rxml.h index 3ee1109601..c3f3335c19 100644 --- a/libretro-common/include/formats/rxml.h +++ b/libretro-common/include/formats/rxml.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2010-2015 The RetroArch team +/* Copyright (C) 2010-2016 The RetroArch team * * --------------------------------------------------------------------------------------- * The following license statement only applies to this file (rxml.h). diff --git a/libretro-common/include/glsym/glsym_es3.h b/libretro-common/include/glsym/glsym_es3.h new file mode 100644 index 0000000000..996b9d2760 --- /dev/null +++ b/libretro-common/include/glsym/glsym_es3.h @@ -0,0 +1,35 @@ +#ifndef RGLGEN_DECL_H__ +#define RGLGEN_DECL_H__ +#ifdef __cplusplus +extern "C" { +#endif +#ifdef GL_APIENTRY +typedef void (GL_APIENTRY *RGLGENGLDEBUGPROC)(GLenum, GLenum, GLuint, GLenum, GLsizei, const GLchar*, GLvoid*); +#else +#ifndef APIENTRY +#define APIENTRY +#endif +#ifndef APIENTRYP +#define APIENTRYP APIENTRY * +#endif +typedef void (APIENTRY *RGLGENGLDEBUGPROCARB)(GLenum, GLenum, GLuint, GLenum, GLsizei, const GLchar*, GLvoid*); +typedef void (APIENTRY *RGLGENGLDEBUGPROC)(GLenum, GLenum, GLuint, GLenum, GLsizei, const GLchar*, GLvoid*); +#endif +#ifndef GL_OES_EGL_image +typedef void *GLeglImageOES; +#endif +#if !defined(GL_OES_fixed_point) && !defined(HAVE_OPENGLES2) +typedef GLint GLfixed; +#endif + + + + + + +struct rglgen_sym_map { const char *sym; void *ptr; }; +extern const struct rglgen_sym_map rglgen_symbol_map[]; +#ifdef __cplusplus +} +#endif +#endif diff --git a/libretro.h b/libretro-common/include/libretro.h similarity index 100% rename from libretro.h rename to libretro-common/include/libretro.h diff --git a/libretro_vulkan.h b/libretro-common/include/libretro_vulkan.h similarity index 99% rename from libretro_vulkan.h rename to libretro-common/include/libretro_vulkan.h index 01e310bc7b..55375e1399 100644 --- a/libretro_vulkan.h +++ b/libretro-common/include/libretro_vulkan.h @@ -23,7 +23,7 @@ #ifndef LIBRETRO_VULKAN_H__ #define LIBRETRO_VULKAN_H__ -#include "libretro.h" +#include #include #define RETRO_HW_RENDER_INTERFACE_VULKAN_VERSION 2 diff --git a/libretro-common/include/retro_dirent.h b/libretro-common/include/retro_dirent.h index 65af28d11d..9b4f53b1d2 100644 --- a/libretro-common/include/retro_dirent.h +++ b/libretro-common/include/retro_dirent.h @@ -49,7 +49,7 @@ const char *retro_dirent_get_name(struct RDIR *rdir); * Returns: true if directory listing entry is * a directory, false if not. */ -bool retro_dirent_is_dir(struct RDIR *rdir); +bool retro_dirent_is_dir(struct RDIR *rdir, const char *path); void retro_closedir(struct RDIR *rdir); diff --git a/libretro-common/lists/dir_list.c b/libretro-common/lists/dir_list.c index 5fb2b373e3..8bcb3f3fbe 100644 --- a/libretro-common/lists/dir_list.c +++ b/libretro-common/lists/dir_list.c @@ -188,7 +188,7 @@ struct string_list *dir_list_new(const char *dir, const char *file_ext = path_get_extension(name); fill_pathname_join(file_path, dir, name, sizeof(file_path)); - is_dir = retro_dirent_is_dir(entry); + is_dir = retro_dirent_is_dir(entry, file_path); ret = parse_dir_entry(name, file_path, is_dir, include_dirs, include_compressed, list, ext_list, file_ext); diff --git a/managers/core_option_manager.c b/managers/core_option_manager.c index 466f10352d..f5075a9365 100644 --- a/managers/core_option_manager.c +++ b/managers/core_option_manager.c @@ -24,7 +24,7 @@ #include #include -#include "../libretro.h" +#include #include "core_option_manager.h" diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index c129b1d76c..c9d9a25328 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -772,7 +772,7 @@ static int generic_action_ok(const char *path, flush_type = MENU_SETTINGS; menu_display_set_msg_force(true); - if (rarch_ctl(RARCH_CTL_REPLACE_CONFIG, action_path)) + if (retroarch_replace_config(action_path)) { bool pending_push = false; menu_navigation_ctl(MENU_NAVIGATION_CTL_CLEAR, &pending_push); @@ -1259,6 +1259,7 @@ static int action_ok_save_state(const char *path, } #ifdef HAVE_NETWORKING +#ifdef HAVE_ZLIB static void cb_decompressed(void *task_data, void *user_data, const char *err) { decompress_task_data_t *dec = (decompress_task_data_t*)task_data; @@ -1289,6 +1290,7 @@ static void cb_decompressed(void *task_data, void *user_data, const char *err) free(dec); } } +#endif /* expects http_transfer_t*, menu_file_transfer_t* */ static void cb_generic_download(void *task_data, diff --git a/menu/drivers/menu_generic.c b/menu/drivers/menu_generic.c index c1bd67114d..95140707b9 100644 --- a/menu/drivers/menu_generic.c +++ b/menu/drivers/menu_generic.c @@ -17,6 +17,7 @@ #include #include +#include #include "menu_generic.h" @@ -28,7 +29,6 @@ #include "../menu_entries.h" #include "../../configuration.h" -#include "../../performance.h" #include "../../performance_counters.h" #include "../../input/input_autodetect.h" #include "../../input/input_config.h" diff --git a/menu/intl/menu_hash_it.c b/menu/intl/menu_hash_it.c index 88e58073a3..b19195cba1 100644 --- a/menu/intl/menu_hash_it.c +++ b/menu/intl/menu_hash_it.c @@ -352,7 +352,9 @@ const char *menu_hash_to_str_it(uint32_t hash) case MENU_LABEL_VALUE_PAUSE_NONACTIVE: return "Non caricare in background"; case MENU_LABEL_VALUE_UI_COMPANION_START_ON_BOOT: - return "Avvia UI Companion all'avvio"; + return "Abilita UI Companion all'avvio"; + case MENU_LABEL_VALUE_UI_COMPANION_ENABLE: + return "Abilita UI Companion"; case MENU_LABEL_VALUE_UI_MENUBAR_ENABLE: return "Barra dei menù"; case MENU_LABEL_VALUE_ARCHIVE_MODE: @@ -587,8 +589,10 @@ const char *menu_hash_to_str_it(uint32_t hash) return "Settaggi"; case MENU_LABEL_VALUE_QUIT_RETROARCH: return "Esci da RetroArch"; - case MENU_LABEL_VALUE_SHUTDOWN: + case MENU_LABEL_VALUE_SHUTDOWN: return "Spegni"; + case MENU_LABEL_VALUE_REBOOT: + return "Riavvia"; case MENU_LABEL_VALUE_HELP: return "Aiuto"; case MENU_LABEL_VALUE_SAVE_NEW_CONFIG: @@ -924,7 +928,7 @@ const char *menu_hash_to_str_it(uint32_t hash) case MENU_LABEL_VALUE_DIRECTORY_SETTINGS: return "Directory"; case MENU_LABEL_VALUE_RECORDING_SETTINGS: - return "Registrando"; + return "Registrazione"; case MENU_LABEL_VALUE_NO_INFORMATION_AVAILABLE: return "Nessuna informazione disponibile."; case MENU_LABEL_VALUE_INPUT_USER_BINDS: @@ -967,6 +971,12 @@ const char *menu_hash_to_str_it(uint32_t hash) return "Cerca:"; case MENU_LABEL_VALUE_USE_BUILTIN_IMAGE_VIEWER: return "Usa visualizzatore di immagini interno"; + case MENU_LABEL_VALUE_ENABLE: + return "Attivare"; + case MENU_LABEL_VALUE_START_CORE: + return "Avvia Core"; + case MENU_LABEL_VALUE_INPUT_POLL_TYPE_BEHAVIOR: + return "Tipo di ritardo"; default: break; } diff --git a/menu/menu_animation.c b/menu/menu_animation.c index db267ec8fb..1f58a26ede 100644 --- a/menu/menu_animation.c +++ b/menu/menu_animation.c @@ -16,13 +16,14 @@ #include #include + #include #include #include +#include #include "menu_animation.h" #include "../configuration.h" -#include "../performance.h" #include "../performance_counters.h" #define IDEAL_DELTA_TIME (1.0 / 60.0 * 1000000.0) diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index eb902a4c99..66fdcd1c7f 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -619,7 +619,7 @@ static int menu_displaylist_parse_system_info(menu_displaylist_info_t *info) strlcpy(tmp, menu_hash_to_str(MENU_LABEL_VALUE_SYSTEM_INFO_GIT_VERSION), sizeof(tmp)); strlcat(tmp, ": ", sizeof(tmp)); - strlcat(tmp, rarch_git_version, sizeof(tmp)); + strlcat(tmp, retroarch_git_version, sizeof(tmp)); menu_entries_add(info->list, tmp, "", MENU_SETTINGS_CORE_INFO_NONE, 0, 0); #endif diff --git a/menu/menu_driver.c b/menu/menu_driver.c index a7ebcfac2a..006820a9c6 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -761,7 +761,7 @@ bool menu_driver_ctl(enum rarch_menu_ctl_state state, void *data) if (!latch) return false; - if (menu_driver_ctx->toggle) + if (menu_driver_ctx && menu_driver_ctx->toggle) menu_driver_ctx->toggle(menu_userdata, *latch); } break; diff --git a/menu/menu_input.c b/menu/menu_input.c index 0025dd668d..64a5c65eea 100644 --- a/menu/menu_input.c +++ b/menu/menu_input.c @@ -27,6 +27,8 @@ #include #include +#include + #include "menu_driver.h" #include "menu_input.h" #include "menu_animation.h" @@ -39,7 +41,6 @@ #include "../general.h" #include "../managers/cheat_manager.h" -#include "../performance.h" #include "../performance_counters.h" #include "../core.h" #include "../input/input_joypad_driver.h" diff --git a/menu/menu_setting.c b/menu/menu_setting.c index d6e20db97a..0959b2ccc7 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -3638,7 +3638,7 @@ static bool setting_append_list( &group_info, &subgroup_info, parent_group); - menu_settings_list_current_add_cmd(list, list_info, CMD_EVENT_QUIT_RETROARCH); + menu_settings_list_current_add_cmd(list, list_info, CMD_EVENT_QUIT); #endif #if defined(HAVE_LAKKA) @@ -4594,7 +4594,7 @@ static bool setting_append_list( &subgroup_info, parent_group); -#if defined(HAVE_THREADS) && !defined(RARCH_CONSOLE) +#if defined(HAVE_THREADS) CONFIG_BOOL( list, list_info, &settings->video.threaded, @@ -5454,7 +5454,6 @@ static bool setting_append_list( &subgroup_info, parent_group); -#ifndef RARCH_CONSOLE CONFIG_BOOL( list, list_info, &settings->video.font_enable, @@ -5468,7 +5467,6 @@ static bool setting_append_list( parent_group, general_write_handler, general_read_handler); -#endif CONFIG_PATH( list, list_info, diff --git a/network/net_http_special.c b/network/net_http_special.c index 2c488c614c..f074510ca4 100644 --- a/network/net_http_special.c +++ b/network/net_http_special.c @@ -17,8 +17,8 @@ #include #include +#include -#include "../performance.h" #include "../performance_counters.h" #include "net_http_special.h" diff --git a/network/net_http_special.h b/network/net_http_special.h index de8c305153..6fa1af0fa8 100644 --- a/network/net_http_special.h +++ b/network/net_http_special.h @@ -17,7 +17,7 @@ #ifndef __NET_HTTP_SPECIAL_H #define __NET_HTTP_SPECIAL_H -#include "../libretro.h" +#include enum { diff --git a/network/netplay.c b/network/netplay.c index 2a26c5b523..2491f569a8 100644 --- a/network/netplay.c +++ b/network/netplay.c @@ -589,7 +589,7 @@ int16_t input_state_net(unsigned port, unsigned device, #ifndef HAVE_SOCKET_LEGACY /* Custom inet_ntop. Win32 doesn't seem to support this ... */ -void np_log_connection(const struct sockaddr_storage *their_addr, +void netplay_log_connection(const struct sockaddr_storage *their_addr, unsigned slot, const char *nick) { union diff --git a/network/netplay.h b/network/netplay.h index 8015c4c428..8f22abc60a 100644 --- a/network/netplay.h +++ b/network/netplay.h @@ -22,8 +22,8 @@ #include #include +#include -#include "../libretro.h" #include "../core.h" typedef struct netplay netplay_t; diff --git a/network/netplay_common.c b/network/netplay_common.c index f6bc3deb0b..7d438e3525 100644 --- a/network/netplay_common.c +++ b/network/netplay_common.c @@ -18,7 +18,7 @@ #include #include "../content.h" -bool np_get_nickname(netplay_t *netplay, int fd) +bool netplay_get_nickname(netplay_t *netplay, int fd) { uint8_t nick_size; @@ -42,7 +42,7 @@ bool np_get_nickname(netplay_t *netplay, int fd) return true; } -bool np_send_nickname(netplay_t *netplay, int fd) +bool netplay_send_nickname(netplay_t *netplay, int fd) { uint8_t nick_size = strlen(netplay->nick); @@ -61,7 +61,7 @@ bool np_send_nickname(netplay_t *netplay, int fd) return true; } -uint32_t *np_bsv_header_generate(size_t *size, uint32_t magic) +uint32_t *netplay_bsv_header_generate(size_t *size, uint32_t magic) { retro_ctx_serialize_info_t serial_info; retro_ctx_size_info_t info; @@ -100,7 +100,7 @@ error: return NULL; } -bool np_bsv_parse_header(const uint32_t *header, uint32_t magic) +bool netplay_bsv_parse_header(const uint32_t *header, uint32_t magic) { retro_ctx_size_info_t info; uint32_t *content_crc_ptr; @@ -146,7 +146,7 @@ bool np_bsv_parse_header(const uint32_t *header, uint32_t magic) } /** - * np_impl_magic: + * netplay_impl_magic: * * Not really a hash, but should be enough to differentiate * implementations from each other. @@ -155,7 +155,7 @@ bool np_bsv_parse_header(const uint32_t *header, uint32_t magic) * The alternative would have been checking serialization sizes, but it * was troublesome for cross platform compat. **/ -uint32_t np_impl_magic(void) +uint32_t netplay_impl_magic(void) { size_t i, len; retro_ctx_api_info_t api_info; @@ -193,7 +193,7 @@ uint32_t np_impl_magic(void) return res; } -bool np_send_info(netplay_t *netplay) +bool netplay_send_info(netplay_t *netplay) { unsigned sram_size; retro_ctx_memory_info_t mem_info; @@ -208,13 +208,13 @@ bool np_send_info(netplay_t *netplay) content_get_crc(&content_crc_ptr); header[0] = htonl(*content_crc_ptr); - header[1] = htonl(np_impl_magic()); + header[1] = htonl(netplay_impl_magic()); header[2] = htonl(mem_info.size); if (!socket_send_all_blocking(netplay->fd, header, sizeof(header), false)) return false; - if (!np_send_nickname(netplay, netplay->fd)) + if (!netplay_send_nickname(netplay, netplay->fd)) { RARCH_ERR("Failed to send nick to host.\n"); return false; @@ -230,7 +230,7 @@ bool np_send_info(netplay_t *netplay) return false; } - if (!np_get_nickname(netplay, netplay->fd)) + if (!netplay_get_nickname(netplay, netplay->fd)) { RARCH_ERR("Failed to receive nick from host.\n"); return false; @@ -243,7 +243,7 @@ bool np_send_info(netplay_t *netplay) return true; } -bool np_get_info(netplay_t *netplay) +bool netplay_get_info(netplay_t *netplay) { unsigned sram_size; uint32_t header[3]; @@ -265,7 +265,7 @@ bool np_get_info(netplay_t *netplay) return false; } - if (np_impl_magic() != ntohl(header[1])) + if (netplay_impl_magic() != ntohl(header[1])) { RARCH_ERR("Implementations differ, make sure you're using exact same " "libretro implementations and RetroArch version.\n"); @@ -282,7 +282,7 @@ bool np_get_info(netplay_t *netplay) return false; } - if (!np_get_nickname(netplay, netplay->fd)) + if (!netplay_get_nickname(netplay, netplay->fd)) { RARCH_ERR("Failed to get nickname from client.\n"); return false; @@ -298,27 +298,27 @@ bool np_get_info(netplay_t *netplay) return false; } - if (!np_send_nickname(netplay, netplay->fd)) + if (!netplay_send_nickname(netplay, netplay->fd)) { RARCH_ERR("Failed to send nickname to client.\n"); return false; } #ifndef HAVE_SOCKET_LEGACY - np_log_connection(&netplay->other_addr, 0, netplay->other_nick); + netplay_log_connection(&netplay->other_addr, 0, netplay->other_nick); #endif return true; } -bool np_is_server(netplay_t* netplay) +bool netplay_is_server(netplay_t* netplay) { if (!netplay) return false; return netplay->is_server; } -bool np_is_spectate(netplay_t* netplay) +bool netplay_is_spectate(netplay_t* netplay) { if (!netplay) return false; diff --git a/network/netplay_net.c b/network/netplay_net.c index 42a224f77a..d119c73c53 100644 --- a/network/netplay_net.c +++ b/network/netplay_net.c @@ -137,14 +137,14 @@ static bool netplay_net_init_buffers(netplay_t *netplay) static bool netplay_net_info_cb(netplay_t* netplay, unsigned frames) { - if (np_is_server(netplay)) + if (netplay_is_server(netplay)) { - if (!np_send_info(netplay)) + if (!netplay_send_info(netplay)) return false; } else { - if (!np_get_info(netplay)) + if (!netplay_get_info(netplay)) return false; } diff --git a/network/netplay_private.h b/network/netplay_private.h index d1d7e8b489..e52ceae46a 100644 --- a/network/netplay_private.h +++ b/network/netplay_private.h @@ -16,6 +16,7 @@ #ifndef __RARCH_NETPLAY_PRIVATE_H #define __RARCH_NETPLAY_PRIVATE_H + #include "netplay.h" #include @@ -138,17 +139,18 @@ extern void *netplay_data; struct netplay_callbacks* netplay_get_cbs_net(void); struct netplay_callbacks* netplay_get_cbs_spectate(void); -void np_log_connection(const struct sockaddr_storage *their_addr, +void netplay_log_connection(const struct sockaddr_storage *their_addr, unsigned slot, const char *nick); -bool np_get_nickname(netplay_t *netplay, int fd); -bool np_send_nickname(netplay_t *netplay, int fd); -bool np_send_info(netplay_t *netplay); -uint32_t *np_bsv_header_generate(size_t *size, uint32_t magic); -bool np_bsv_parse_header(const uint32_t *header, uint32_t magic); -uint32_t np_impl_magic(void); -bool np_send_info(netplay_t *netplay); -bool np_get_info(netplay_t *netplay); -bool np_is_server(netplay_t* netplay); -bool np_is_spectate(netplay_t* netplay); +bool netplay_get_nickname(netplay_t *netplay, int fd); +bool netplay_send_nickname(netplay_t *netplay, int fd); +bool netplay_send_info(netplay_t *netplay); +uint32_t *netplay_bsv_header_generate(size_t *size, uint32_t magic); +bool netplay_bsv_parse_header(const uint32_t *header, uint32_t magic); +uint32_t netplay_impl_magic(void); +bool netplay_send_info(netplay_t *netplay); +bool netplay_get_info(netplay_t *netplay); +bool netplay_is_server(netplay_t* netplay); +bool netplay_is_spectate(netplay_t* netplay); + #endif diff --git a/network/netplay_spectate.c b/network/netplay_spectate.c index d257c61212..455b4de174 100644 --- a/network/netplay_spectate.c +++ b/network/netplay_spectate.c @@ -41,7 +41,7 @@ static void netplay_spectate_pre_frame(netplay_t *netplay) fd_set fds; struct timeval tmp_tv = {0}; - if (!np_is_server(netplay)) + if (!netplay_is_server(netplay)) return; FD_ZERO(&fds); @@ -78,22 +78,22 @@ static void netplay_spectate_pre_frame(netplay_t *netplay) return; } - if (!np_get_nickname(netplay, new_fd)) + if (!netplay_get_nickname(netplay, new_fd)) { RARCH_ERR("Failed to get nickname from client.\n"); socket_close(new_fd); return; } - if (!np_send_nickname(netplay, new_fd)) + if (!netplay_send_nickname(netplay, new_fd)) { RARCH_ERR("Failed to send nickname to client.\n"); socket_close(new_fd); return; } - header = np_bsv_header_generate(&header_size, - np_impl_magic()); + header = netplay_bsv_header_generate(&header_size, + netplay_impl_magic()); if (!header) { @@ -118,7 +118,7 @@ static void netplay_spectate_pre_frame(netplay_t *netplay) netplay->spectate.fds[idx] = new_fd; #ifndef HAVE_SOCKET_LEGACY - np_log_connection(&their_addr, idx, netplay->other_nick); + netplay_log_connection(&their_addr, idx, netplay->other_nick); #endif } @@ -133,7 +133,7 @@ static void netplay_spectate_post_frame(netplay_t *netplay) { unsigned i; - if (!np_is_server(netplay)) + if (!netplay_is_server(netplay)) return; for (i = 0; i < MAX_SPECTATORS; i++) @@ -165,9 +165,9 @@ static void netplay_spectate_post_frame(netplay_t *netplay) static bool netplay_spectate_info_cb(netplay_t *netplay, unsigned frames) { unsigned i; - if(np_is_server(netplay)) + if(netplay_is_server(netplay)) { - if(!np_get_info(netplay)) + if(!netplay_get_info(netplay)) return false; } diff --git a/performance.c b/performance.c deleted file mode 100644 index b165192103..0000000000 --- a/performance.c +++ /dev/null @@ -1,566 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2010-2014 - Hans-Kristian Arntzen - * Copyright (C) 2011-2016 - 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 "libretro.h" -#include "performance.h" -#include "general.h" -#include "compat/strl.h" -#include "verbosity.h" - -#ifdef _WIN32 -#define PERF_LOG_FMT "[PERF]: Avg (%s): %I64u ticks, %I64u runs.\n" -#else -#define PERF_LOG_FMT "[PERF]: Avg (%s): %llu ticks, %llu runs.\n" -#endif - -#if defined(_WIN32) -#include -#else -#include -#endif - -#if defined(_WIN32) && !defined(_XBOX) -#include -#include -#endif - -#if defined(__CELLOS_LV2__) -#ifndef _PPU_INTRINSICS_H -#include -#endif -#elif defined(_XBOX360) -#include -#elif defined(_POSIX_MONOTONIC_CLOCK) || defined(ANDROID) || defined(__QNX__) -/* POSIX_MONOTONIC_CLOCK is not being defined in Android headers despite support being present. */ -#include -#endif - -#if defined(__QNX__) && !defined(CLOCK_MONOTONIC) -#define CLOCK_MONOTONIC 2 -#endif - -#if defined(PSP) -#include -#include -#endif - -#if defined(VITA) -#include -#include -#endif - -#if defined(__PSL1GHT__) -#include -#elif defined(__CELLOS_LV2__) -#include -#endif - -#ifdef GEKKO -#include -#endif - -/* iOS/OSX specific. Lacks clock_gettime(), so implement it. */ -#ifdef __MACH__ -#include - -#ifndef CLOCK_MONOTONIC -#define CLOCK_MONOTONIC 0 -#endif - -#ifndef CLOCK_REALTIME -#define CLOCK_REALTIME 0 -#endif - -static int clock_gettime(int clk_ik, struct timespec *t) -{ - struct timeval now; - int rv = gettimeofday(&now, NULL); - if (rv) - return rv; - t->tv_sec = now.tv_sec; - t->tv_nsec = now.tv_usec * 1000; - return 0; -} -#endif - -#ifdef EMSCRIPTEN -#include -#endif - -#if defined(BSD) || defined(__APPLE__) -#include -#endif - -#include - -#if defined(__linux__) -#include "frontend/drivers/platform_linux.h" -#endif - -/** - * cpu_features_get_perf_counter: - * - * Gets performance counter. - * - * Returns: performance counter. - **/ -retro_perf_tick_t cpu_features_get_perf_counter(void) -{ - retro_perf_tick_t time_ticks = 0; -#if defined(__linux__) || defined(__QNX__) || defined(__MACH__) - struct timespec tv; - if (clock_gettime(CLOCK_MONOTONIC, &tv) == 0) - time_ticks = (retro_perf_tick_t)tv.tv_sec * 1000000000 + - (retro_perf_tick_t)tv.tv_nsec; - -#elif defined(__GNUC__) && defined(__i386__) || defined(__i486__) || defined(__i686__) - __asm__ volatile ("rdtsc" : "=A" (time_ticks)); -#elif defined(__GNUC__) && defined(__x86_64__) - unsigned a, d; - __asm__ volatile ("rdtsc" : "=a" (a), "=d" (d)); - time_ticks = (retro_perf_tick_t)a | ((retro_perf_tick_t)d << 32); -#elif defined(__ARM_ARCH_6__) - __asm__ volatile( "mrc p15, 0, %0, c9, c13, 0" : "=r"(time_ticks) ); -#elif defined(__CELLOS_LV2__) || defined(_XBOX360) || defined(__powerpc__) || defined(__ppc__) || defined(__POWERPC__) - time_ticks = __mftb(); -#elif defined(GEKKO) - time_ticks = gettime(); -#elif defined(PSP) || defined(VITA) - sceRtcGetCurrentTick(&time_ticks); -#elif defined(_3DS) - time_ticks = svcGetSystemTick(); -#elif defined(__mips__) - struct timeval tv; - gettimeofday(&tv,NULL); - time_ticks = (1000000 * tv.tv_sec + tv.tv_usec); -#elif defined(_WIN32) - long tv_sec, tv_usec; - static const unsigned __int64 epoch = 11644473600000000Ui64; - FILETIME file_time; - SYSTEMTIME system_time; - ULARGE_INTEGER ularge; - - GetSystemTime(&system_time); - SystemTimeToFileTime(&system_time, &file_time); - ularge.LowPart = file_time.dwLowDateTime; - ularge.HighPart = file_time.dwHighDateTime; - - tv_sec = (long)((ularge.QuadPart - epoch) / 10000000L); - tv_usec = (long)(system_time.wMilliseconds * 1000); - - time_ticks = (1000000 * tv_sec + tv_usec); -#endif - - return time_ticks; -} - -/** - * cpu_features_get_time_usec: - * - * Gets time in microseconds. - * - * Returns: time in microseconds. - **/ -retro_time_t cpu_features_get_time_usec(void) -{ -#if defined(_WIN32) - static LARGE_INTEGER freq; - LARGE_INTEGER count; - - /* Frequency is guaranteed to not change. */ - if (!freq.QuadPart && !QueryPerformanceFrequency(&freq)) - return 0; - - if (!QueryPerformanceCounter(&count)) - return 0; - return count.QuadPart * 1000000 / freq.QuadPart; -#elif defined(__CELLOS_LV2__) - return sys_time_get_system_time(); -#elif defined(GEKKO) - return ticks_to_microsecs(gettime()); -#elif defined(_POSIX_MONOTONIC_CLOCK) || defined(__QNX__) || defined(ANDROID) || defined(__MACH__) - struct timespec tv = {0}; - if (clock_gettime(CLOCK_MONOTONIC, &tv) < 0) - return 0; - return tv.tv_sec * INT64_C(1000000) + (tv.tv_nsec + 500) / 1000; -#elif defined(EMSCRIPTEN) - return emscripten_get_now() * 1000; -#elif defined(__mips__) - struct timeval tv; - gettimeofday(&tv,NULL); - return (1000000 * tv.tv_sec + tv.tv_usec); -#elif defined(_3DS) - return osGetTime() * 1000; -#elif defined(VITA) - return sceKernelGetProcessTimeWide(); -#else -#error "Your platform does not have a timer function implemented in cpu_features_get_time_usec(). Cannot continue." -#endif -} - -#if defined(__x86_64__) || defined(__i386__) || defined(__i486__) || defined(__i686__) -#define CPU_X86 -#endif - -#if defined(_MSC_VER) && !defined(_XBOX) -#include -#endif - -#if defined(CPU_X86) && !defined(__MACH__) -void x86_cpuid(int func, int flags[4]) -{ - /* On Android, we compile RetroArch with PIC, and we - * are not allowed to clobber the ebx register. */ -#ifdef __x86_64__ -#define REG_b "rbx" -#define REG_S "rsi" -#else -#define REG_b "ebx" -#define REG_S "esi" -#endif - -#if defined(__GNUC__) - __asm__ volatile ( - "mov %%" REG_b ", %%" REG_S "\n" - "cpuid\n" - "xchg %%" REG_b ", %%" REG_S "\n" - : "=a"(flags[0]), "=S"(flags[1]), "=c"(flags[2]), "=d"(flags[3]) - : "a"(func)); -#elif defined(_MSC_VER) - __cpuid(flags, func); -#else - printf("Unknown compiler. Cannot check CPUID with inline assembly.\n"); - memset(flags, 0, 4 * sizeof(int)); -#endif -} - -/* Only runs on i686 and above. Needs to be conditionally run. */ -static uint64_t xgetbv_x86(uint32_t idx) -{ -#if defined(__GNUC__) - uint32_t eax, edx; - __asm__ volatile ( - /* Older GCC versions (Apple's GCC for example) do - * not understand xgetbv instruction. - * Stamp out the machine code directly. - */ - ".byte 0x0f, 0x01, 0xd0\n" - : "=a"(eax), "=d"(edx) : "c"(idx)); - return ((uint64_t)edx << 32) | eax; -#elif _MSC_FULL_VER >= 160040219 - /* Intrinsic only works on 2010 SP1 and above. */ - return _xgetbv(idx); -#else - printf("Unknown compiler. Cannot check xgetbv bits.\n"); - return 0; -#endif -} -#endif - -#if defined(__ARM_NEON__) -static void arm_enable_runfast_mode(void) -{ - /* RunFast mode. Enables flush-to-zero and some - * floating point optimizations. */ - static const unsigned x = 0x04086060; - static const unsigned y = 0x03000000; - int r; - __asm__ volatile( - "fmrx %0, fpscr \n\t" /* r0 = FPSCR */ - "and %0, %0, %1 \n\t" /* r0 = r0 & 0x04086060 */ - "orr %0, %0, %2 \n\t" /* r0 = r0 | 0x03000000 */ - "fmxr fpscr, %0 \n\t" /* FPSCR = r0 */ - : "=r"(r) - : "r"(x), "r"(y) - ); -} -#endif - -/** - * cpu_features_get_core_amount: - * - * Gets the amount of available CPU cores. - * - * Returns: amount of CPU cores available. - **/ -unsigned cpu_features_get_core_amount(void) -{ -#if defined(_WIN32) && !defined(_XBOX) - /* Win32 */ - SYSTEM_INFO sysinfo; - GetSystemInfo(&sysinfo); - return sysinfo.dwNumberOfProcessors; -#elif defined(GEKKO) - return 1; -#elif defined(PSP) - return 1; -#elif defined(VITA) - return 4; -#elif defined(_3DS) - return 1; -#elif defined(_SC_NPROCESSORS_ONLN) - /* Linux, most UNIX-likes. */ - long ret = sysconf(_SC_NPROCESSORS_ONLN); - if (ret <= 0) - return (unsigned)1; - return ret; -#elif defined(BSD) || defined(__APPLE__) - /* BSD */ - /* Copypasta from stackoverflow, dunno if it works. */ - int num_cpu = 0; - int mib[4]; - size_t len = sizeof(num_cpu); - - mib[0] = CTL_HW; - mib[1] = HW_AVAILCPU; - sysctl(mib, 2, &num_cpu, &len, NULL, 0); - if (num_cpu < 1) - { - mib[1] = HW_NCPU; - sysctl(mib, 2, &num_cpu, &len, NULL, 0); - if (num_cpu < 1) - num_cpu = 1; - } - return num_cpu; -#elif defined(__linux__) - return linux_get_cpu_count(); -#elif defined(_XBOX360) - return 3; -#else - /* No idea, assume single core. */ - return 1; -#endif -} - -/* According to http://en.wikipedia.org/wiki/CPUID */ -#define VENDOR_INTEL_b 0x756e6547 -#define VENDOR_INTEL_c 0x6c65746e -#define VENDOR_INTEL_d 0x49656e69 - -/** - * cpu_features_get: - * - * Gets CPU features.. - * - * Returns: bitmask of all CPU features available. - **/ -uint64_t cpu_features_get(void) -{ - int flags[4]; - int vendor_shuffle[3]; - char vendor[13] = {0}; - size_t len = 0; - uint64_t cpu_flags = 0; - uint64_t cpu = 0; - unsigned max_flag = 0; -#if defined(CPU_X86) && !defined(__MACH__) - int vendor_is_intel = 0; - const int avx_flags = (1 << 27) | (1 << 28); -#endif - - char buf[sizeof(" MMX MMXEXT SSE SSE2 SSE3 SSSE3 SS4 SSE4.2 AES AVX AVX2 NEON VMX VMX128 VFPU PS")]; - - memset(buf, 0, sizeof(buf)); - - (void)len; - (void)cpu_flags; - (void)flags; - (void)max_flag; - (void)vendor; - (void)vendor_shuffle; - -#if defined(__MACH__) - len = sizeof(size_t); - if (sysctlbyname("hw.optional.mmx", NULL, &len, NULL, 0) == 0) - { - cpu |= CPU_FEATURE_MMX; - cpu |= CPU_FEATURE_MMXEXT; - } - - len = sizeof(size_t); - if (sysctlbyname("hw.optional.sse", NULL, &len, NULL, 0) == 0) - cpu |= CPU_FEATURE_SSE; - - len = sizeof(size_t); - if (sysctlbyname("hw.optional.sse2", NULL, &len, NULL, 0) == 0) - cpu |= CPU_FEATURE_SSE2; - - len = sizeof(size_t); - if (sysctlbyname("hw.optional.sse3", NULL, &len, NULL, 0) == 0) - cpu |= CPU_FEATURE_SSE3; - - len = sizeof(size_t); - if (sysctlbyname("hw.optional.supplementalsse3", NULL, &len, NULL, 0) == 0) - cpu |= CPU_FEATURE_SSSE3; - - len = sizeof(size_t); - if (sysctlbyname("hw.optional.sse4_1", NULL, &len, NULL, 0) == 0) - cpu |= CPU_FEATURE_SSE4; - - len = sizeof(size_t); - if (sysctlbyname("hw.optional.sse4_2", NULL, &len, NULL, 0) == 0) - cpu |= CPU_FEATURE_SSE42; - - len = sizeof(size_t); - if (sysctlbyname("hw.optional.aes", NULL, &len, NULL, 0) == 0) - cpu |= CPU_FEATURE_AES; - - len = sizeof(size_t); - if (sysctlbyname("hw.optional.avx1_0", NULL, &len, NULL, 0) == 0) - cpu |= CPU_FEATURE_AVX; - - len = sizeof(size_t); - if (sysctlbyname("hw.optional.avx2_0", NULL, &len, NULL, 0) == 0) - cpu |= CPU_FEATURE_AVX2; - - len = sizeof(size_t); - if (sysctlbyname("hw.optional.altivec", NULL, &len, NULL, 0) == 0) - cpu |= CPU_FEATURE_VMX; - - len = sizeof(size_t); - if (sysctlbyname("hw.optional.neon", NULL, &len, NULL, 0) == 0) - cpu |= CPU_FEATURE_NEON; - -#elif defined(CPU_X86) - (void)avx_flags; - - x86_cpuid(0, flags); - vendor_shuffle[0] = flags[1]; - vendor_shuffle[1] = flags[3]; - vendor_shuffle[2] = flags[2]; - memcpy(vendor, vendor_shuffle, sizeof(vendor_shuffle)); - - printf("[CPUID]: Vendor: %s\n", vendor); - - vendor_is_intel = ( - flags[1] == VENDOR_INTEL_b && - flags[2] == VENDOR_INTEL_c && - flags[3] == VENDOR_INTEL_d); - - max_flag = flags[0]; - if (max_flag < 1) /* Does CPUID not support func = 1? (unlikely ...) */ - return 0; - - x86_cpuid(1, flags); - - if (flags[3] & (1 << 23)) - cpu |= CPU_FEATURE_MMX; - - if (flags[3] & (1 << 25)) - { - /* SSE also implies MMXEXT (according to FFmpeg source). */ - cpu |= CPU_FEATURE_SSE; - cpu |= CPU_FEATURE_MMXEXT; - } - - - if (flags[3] & (1 << 26)) - cpu |= CPU_FEATURE_SSE2; - - if (flags[2] & (1 << 0)) - cpu |= CPU_FEATURE_SSE3; - - if (flags[2] & (1 << 9)) - cpu |= CPU_FEATURE_SSSE3; - - if (flags[2] & (1 << 19)) - cpu |= CPU_FEATURE_SSE4; - - if (flags[2] & (1 << 20)) - cpu |= CPU_FEATURE_SSE42; - - if ((flags[2] & (1 << 23))) - cpu |= CPU_FEATURE_POPCNT; - - if (vendor_is_intel && (flags[2] & (1 << 22))) - cpu |= CPU_FEATURE_MOVBE; - - if (flags[2] & (1 << 25)) - cpu |= CPU_FEATURE_AES; - - - /* Must only perform xgetbv check if we have - * AVX CPU support (guaranteed to have at least i686). */ - if (((flags[2] & avx_flags) == avx_flags) - && ((xgetbv_x86(0) & 0x6) == 0x6)) - cpu |= CPU_FEATURE_AVX; - - if (max_flag >= 7) - { - x86_cpuid(7, flags); - if (flags[1] & (1 << 5)) - cpu |= CPU_FEATURE_AVX2; - } - - x86_cpuid(0x80000000, flags); - max_flag = flags[0]; - if (max_flag >= 0x80000001u) - { - x86_cpuid(0x80000001, flags); - if (flags[3] & (1 << 23)) - cpu |= CPU_FEATURE_MMX; - if (flags[3] & (1 << 22)) - cpu |= CPU_FEATURE_MMXEXT; - } -#elif defined(__linux__) - cpu_flags = linux_get_cpu_features(); - - if (cpu_flags & CPU_ARM_FEATURE_NEON) - { - cpu |= CPU_FEATURE_NEON; -#ifdef __ARM_NEON__ - arm_enable_runfast_mode(); -#endif - } - - if (cpu_flags & CPU_ARM_FEATURE_VFPv3) - cpu |= CPU_FEATURE_VFPV3; - -#elif defined(__ARM_NEON__) - cpu |= CPU_FEATURE_NEON; - arm_enable_runfast_mode(); -#elif defined(__ALTIVEC__) - cpu |= CPU_FEATURE_VMX; -#elif defined(XBOX360) - cpu |= CPU_FEATURE_VMX128; -#elif defined(PSP) - cpu |= CPU_FEATURE_VFPU; -#elif defined(GEKKO) - cpu |= CPU_FEATURE_PS; -#endif - - if (cpu & CPU_FEATURE_MMX) strlcat(buf, " MMX", sizeof(buf)); - if (cpu & CPU_FEATURE_MMXEXT) strlcat(buf, " MMXEXT", sizeof(buf)); - if (cpu & CPU_FEATURE_SSE) strlcat(buf, " SSE", sizeof(buf)); - if (cpu & CPU_FEATURE_SSE2) strlcat(buf, " SSE2", sizeof(buf)); - if (cpu & CPU_FEATURE_SSE3) strlcat(buf, " SSE3", sizeof(buf)); - if (cpu & CPU_FEATURE_SSSE3) strlcat(buf, " SSSE3", sizeof(buf)); - if (cpu & CPU_FEATURE_SSE4) strlcat(buf, " SSE4", sizeof(buf)); - if (cpu & CPU_FEATURE_SSE42) strlcat(buf, " SSE4.2", sizeof(buf)); - if (cpu & CPU_FEATURE_AES) strlcat(buf, " AES", sizeof(buf)); - if (cpu & CPU_FEATURE_AVX) strlcat(buf, " AVX", sizeof(buf)); - if (cpu & CPU_FEATURE_AVX2) strlcat(buf, " AVX2", sizeof(buf)); - if (cpu & CPU_FEATURE_NEON) strlcat(buf, " NEON", sizeof(buf)); - if (cpu & CPU_FEATURE_VFPV3) strlcat(buf, " VFPv3", sizeof(buf)); - if (cpu & CPU_FEATURE_VFPV4) strlcat(buf, " VFPv4", sizeof(buf)); - if (cpu & CPU_FEATURE_VMX) strlcat(buf, " VMX", sizeof(buf)); - if (cpu & CPU_FEATURE_VMX128) strlcat(buf, " VMX128", sizeof(buf)); - if (cpu & CPU_FEATURE_VFPU) strlcat(buf, " VFPU", sizeof(buf)); - if (cpu & CPU_FEATURE_PS) strlcat(buf, " PS", sizeof(buf)); - - return cpu; -} diff --git a/performance.h b/performance.h deleted file mode 100644 index dac242511d..0000000000 --- a/performance.h +++ /dev/null @@ -1,96 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2010-2014 - Hans-Kristian Arntzen - * Copyright (C) 2011-2016 - 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 . - */ - -#ifndef _LIBRETRO_SDK_CPU_INFO_H -#define _LIBRETRO_SDK_CPU_INFO_H - -#include - -#ifdef RARCH_INTERNAL -#include "libretro.h" -#else -typedef uint64_t retro_perf_tick_t; -typedef uint64_t retro_time_t; -#endif - -/* ID values for CPU features */ -#define CPU_FEATURE_SSE (1 << 0) -#define CPU_FEATURE_SSE2 (1 << 1) -#define CPU_FEATURE_VMX (1 << 2) -#define CPU_FEATURE_VMX128 (1 << 3) -#define CPU_FEATURE_AVX (1 << 4) -#define CPU_FEATURE_NEON (1 << 5) -#define CPU_FEATURE_SSE3 (1 << 6) -#define CPU_FEATURE_SSSE3 (1 << 7) -#define CPU_FEATURE_MMX (1 << 8) -#define CPU_FEATURE_MMXEXT (1 << 9) -#define CPU_FEATURE_SSE4 (1 << 10) -#define CPU_FEATURE_SSE42 (1 << 11) -#define CPU_FEATURE_AVX2 (1 << 12) -#define CPU_FEATURE_VFPU (1 << 13) -#define CPU_FEATURE_PS (1 << 14) -#define CPU_FEATURE_AES (1 << 15) -#define CPU_FEATURE_VFPV3 (1 << 16) -#define CPU_FEATURE_VFPV4 (1 << 17) -#define CPU_FEATURE_POPCNT (1 << 18) -#define CPU_FEATURE_MOVBE (1 << 19) - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * cpu_features_get_perf_counter: - * - * Gets performance counter. - * - * Returns: performance counter. - **/ -retro_perf_tick_t cpu_features_get_perf_counter(void); - -/** - * cpu_features_get_time_usec: - * - * Gets time in microseconds. * - * Returns: time in microseconds. - **/ -retro_time_t cpu_features_get_time_usec(void); - -/** - * cpu_features_get: - * - * Gets CPU features.. - * - * Returns: bitmask of all CPU features available. - **/ -uint64_t cpu_features_get(void); - -/** - * cpu_features_get_core_amount: - * - * Gets the amount of available CPU cores. - * - * Returns: amount of CPU cores available. - **/ -unsigned cpu_features_get_core_amount(void); - - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/performance_counters.c b/performance_counters.c index 209e6fb824..002222ef5c 100644 --- a/performance_counters.c +++ b/performance_counters.c @@ -17,7 +17,14 @@ #include #include -#include "performance.h" +#ifdef _WIN32 +#include +#else +#include +#endif + +#include + #include "performance_counters.h" #include "general.h" @@ -30,10 +37,6 @@ #define PERF_LOG_FMT "[PERF]: Avg (%s): %llu ticks, %llu runs.\n" #endif -#if !defined(_WIN32) && !defined(RARCH_CONSOLE) -#include -#endif - static struct retro_perf_counter *perf_counters_rarch[MAX_COUNTERS]; static struct retro_perf_counter *perf_counters_libretro[MAX_COUNTERS]; static unsigned perf_ptr_rarch; diff --git a/performance_counters.h b/performance_counters.h index c15cc7881a..a992a4baa4 100644 --- a/performance_counters.h +++ b/performance_counters.h @@ -19,7 +19,7 @@ #include -#include "libretro.h" +#include #ifdef __cplusplus extern "C" { diff --git a/pkg/android/phoenix/jni/Android.mk b/pkg/android/phoenix/jni/Android.mk index fac9cf6e7e..5125d92e9c 100644 --- a/pkg/android/phoenix/jni/Android.mk +++ b/pkg/android/phoenix/jni/Android.mk @@ -63,7 +63,7 @@ DEFINES += -DHAVE_CHEEVOS DEFINES += -DHAVE_SL LOCAL_CFLAGS += -Wall -std=gnu99 -pthread -Wno-unused-function -fno-stack-protector -funroll-loops $(DEFINES) -LOCAL_CPPFLAGS := -fno-exceptions -std=gnu++11 -fno-rtti -Wno-reorder $(DEFINES) +LOCAL_CPPFLAGS := -fexceptions -std=gnu++11 -fno-rtti -Wno-reorder $(DEFINES) # Let ndk-build set the optimization flags but remove -O3 like in cf3c3 LOCAL_CFLAGS := $(subst -O3,-O2,$(LOCAL_CFLAGS)) @@ -79,7 +79,8 @@ LOCAL_CPPFLAGS += -I$(LOCAL_PATH)/$(RARCH_DIR)/deps/glslang \ -I$(LOCAL_PATH)/$(RARCH_DIR)/deps/glslang/glslang/glslang/Public \ -I$(LOCAL_PATH)/$(RARCH_DIR)/deps/glslang/glslang/glslang/MachineIndependent \ -I$(LOCAL_PATH)/$(RARCH_DIR)/deps/glslang/glslang/SPIRV \ - -I$(LOCAL_PATH)/$(RARCH_DIR)/deps/spir2cross + -I$(LOCAL_PATH)/$(RARCH_DIR)/deps/spir2cross \ + -I$(LOCAL_PATH)/$(RARCH_DIR)/deps/SPIRV-Cross LOCAL_SRC_FILES += $(RARCH_DIR)/deps/glslang/glslang.cpp \ $(RARCH_DIR)/deps/glslang/glslang/SPIRV/SpvBuilder.cpp \ diff --git a/pkg/android/phoenix/jni/Android2.mk b/pkg/android/phoenix/jni/Android2.mk index 06ec713d76..f1177b051e 100644 --- a/pkg/android/phoenix/jni/Android2.mk +++ b/pkg/android/phoenix/jni/Android2.mk @@ -65,7 +65,7 @@ DEFINES += -DDEBUG_ANDROID DEFINES += -DHAVE_SL LOCAL_CFLAGS += -Wall -std=gnu99 -pthread -Wno-unused-function -fno-stack-protector -funroll-loops $(DEFINES) -LOCAL_CPPFLAGS := -std=gnu++11 $(DEFINES) +LOCAL_CPPFLAGS := -fexceptions -std=gnu++11 -fno-rtti -Wno-reorder $(DEFINES) ifeq ($(NDK_DEBUG),1) LOCAL_CFLAGS += -O0 -g @@ -83,7 +83,10 @@ LOCAL_C_INCLUDES += $(INCFLAGS) LOCAL_CPPFLAGS += -I$(LOCAL_PATH)/$(RARCH_DIR)/deps/glslang \ -I$(LOCAL_PATH)/$(RARCH_DIR)/deps/glslang/glslang/glslang/Public \ -I$(LOCAL_PATH)/$(RARCH_DIR)/deps/glslang/glslang/glslang/MachineIndependent \ - -I$(LOCAL_PATH)/$(RARCH_DIR)/deps/glslang/glslang/SPIRV + -I$(LOCAL_PATH)/$(RARCH_DIR)/deps/glslang/glslang/SPIRV \ + -I$(LOCAL_PATH)/$(RARCH_DIR)/deps/spir2cross \ + -I$(LOCAL_PATH)/$(RARCH_DIR)/deps/SPIRV-Cross + LOCAL_SRC_FILES += $(RARCH_DIR)/deps/glslang/glslang.cpp \ $(RARCH_DIR)/deps/glslang/glslang/SPIRV/SpvBuilder.cpp \ $(RARCH_DIR)/deps/glslang/glslang/SPIRV/SPVRemapper.cpp \ diff --git a/qb/config.libs.sh b/qb/config.libs.sh index 04cdff7566..01859e8ede 100644 --- a/qb/config.libs.sh +++ b/qb/config.libs.sh @@ -403,6 +403,12 @@ if [ "$HAVE_VULKAN" != 'no' ] && [ ! -e deps/glslang/glslang/README.md ]; then HAVE_VULKAN=no fi +if [ "$HAVE_VULKAN" != 'no' ] && [ ! -e deps/SPIRV-Cross/README.md ]; then + echo "Warning: SPIRV-Cross submodule not loaded, can't use Vulkan." + echo "To fix, use: git submodule init && git submodule update" + HAVE_VULKAN=no +fi + check_pkgconf PYTHON python3 if [ "$HAVE_MATERIALUI" != 'no' ] || [ "$HAVE_XMB" != 'no' ] || [ "$HAVE_ZARCH" != 'no' ]; then @@ -410,19 +416,35 @@ if [ "$HAVE_MATERIALUI" != 'no' ] || [ "$HAVE_XMB" != 'no' ] || [ "$HAVE_ZARCH" HAVE_MATERIALUI=no HAVE_XMB=no HAVE_ZARCH=no - echo "Notice: RGUI not available, MaterialUI, XMB and ZARCH will be disabled." + echo "Notice: RGUI not available, MaterialUI, XMB and ZARCH will also be disabled." elif [ "$HAVE_OPENGL" = 'no' ] && [ "$HAVE_GLES" = 'no' ] && [ "$HAVE_VULKAN" = 'no' ]; then HAVE_MATERIALUI=no HAVE_XMB=no HAVE_ZARCH=no - echo "Notice: Hardware rendering context not available, XMB, MaterialUI and ZARCH will be disabled." + echo "Notice: Hardware rendering context not available, XMB, MaterialUI and ZARCH will also be disabled." fi fi + check_macro NEON __ARM_NEON__ add_define_make OS "$OS" +if [ "$HAVE_ZLIB" = 'no' ] && [ "HAVE_RPNG" != 'no' ]; then + HAVE_RPNG=no + echo "Notice: zlib is not available, RPNG will also be disabled." +fi + +if [ "$HAVE_THREADS" = 'no' ] && [ "HAVE_CHEEVOS" != 'no' ]; then + HAVE_CHEEVOS=no + echo "Notice: Threads are not available, Cheevos will also be disabled." +fi + +if [ "$HAVE_THREADS" = 'no' ] && [ "HAVE_LIBUSB" != 'no' ]; then + HAVE_LIBUSB=no + echo "Notice: Threads are not available, libusb will also be disabled." +fi + # Creates config.mk and config.h. add_define_make GLOBAL_CONFIG_DIR "$GLOBAL_CONFIG_DIR" VARS=$(eval set | grep ^HAVE_ | sed s/=.*// | sed s/^HAVE_//) diff --git a/qb/config.params.sh b/qb/config.params.sh index 16c576a2a6..7f89043a61 100644 --- a/qb/config.params.sh +++ b/qb/config.params.sh @@ -77,3 +77,6 @@ HAVE_XSHM=no # XShm video driver support (disabled because it's ju HAVE_CHEEVOS=yes # Retro Achievements HAVE_VULKAN=auto # Vulkan support C89_VULKAN=no +HAVE_RPNG=yes # RPNG support +HAVE_RJPEG=yes # RJPEG support +HAVE_RTGA=yes # RTGA support diff --git a/retroarch.c b/retroarch.c index e0f1cff51f..f4c5fb3ba5 100644 --- a/retroarch.c +++ b/retroarch.c @@ -43,6 +43,8 @@ #include #include +#include + #include "content.h" #include "core_type.h" #include "core_info.h" @@ -58,7 +60,6 @@ #include "configuration.h" #include "general.h" #include "runloop.h" -#include "performance.h" #include "managers/cheat_manager.h" #include "system.h" @@ -175,7 +176,7 @@ static void retroarch_print_version(void) fprintf(stderr, "%s: Frontend for libretro -- v%s", msg_hash_to_str(MSG_PROGRAM), PACKAGE_VERSION); #ifdef HAVE_GIT_VERSION - printf(" -- %s --\n", rarch_git_version); + printf(" -- %s --\n", retroarch_git_version); #endif retroarch_get_capabilities(RARCH_CAPABILITIES_COMPILER, str, sizeof(str)); fprintf(stdout, "%s", str); @@ -1039,7 +1040,7 @@ static void retroarch_parse_input(int argc, char *argv[]) { /* We requested explicit ROM, so use PLAIN core type. */ current_core_type = CORE_TYPE_PLAIN; - rarch_ctl(RARCH_CTL_SET_PATHS, (void*)argv[optind]); + retroarch_set_pathnames((const char*)argv[optind]); } else if (*global->subsystem && optind < argc) { @@ -1210,6 +1211,34 @@ bool retroarch_validate_game_options(char *s, size_t len, bool mkdir) return true; } +#define FAIL_CPU(simd_type) do { \ + RARCH_ERR(simd_type " code is compiled in, but CPU does not support this feature. Cannot continue.\n"); \ + retroarch_fail(1, "validate_cpu_features()"); \ +} while(0) + +/* Validates CPU features for given processor architecture. + * Make sure we haven't compiled for something we cannot run. + * Ideally, code would get swapped out depending on CPU support, + * but this will do for now. */ +static void retroarch_validate_cpu_features(void) +{ + uint64_t cpu = cpu_features_get(); + (void)cpu; + +#ifdef __SSE__ + if (!(cpu & RETRO_SIMD_SSE)) + FAIL_CPU("SSE"); +#endif +#ifdef __SSE2__ + if (!(cpu & RETRO_SIMD_SSE2)) + FAIL_CPU("SSE2"); +#endif +#ifdef __AVX__ + if (!(cpu & RETRO_SIMD_AVX)) + FAIL_CPU("AVX"); +#endif +} + /** * retroarch_main_init: * @argc : Count of (commandline) arguments. @@ -1219,7 +1248,7 @@ bool retroarch_validate_game_options(char *s, size_t len, bool mkdir) * * Returns: 0 on success, otherwise 1 if there was an error. **/ -static int retroarch_main_init(int argc, char *argv[]) +bool retroarch_main_init(int argc, char *argv[]) { int sjlj_ret; bool *verbosity = NULL; @@ -1229,7 +1258,7 @@ static int retroarch_main_init(int argc, char *argv[]) if ((sjlj_ret = setjmp(error_sjlj_context)) > 0) { RARCH_ERR("Fatal error received in: \"%s\"\n", error_string); - return sjlj_ret; + return false; } rarch_ctl(RARCH_CTL_SET_ERROR_ON_INIT, NULL); @@ -1248,12 +1277,12 @@ static int retroarch_main_init(int argc, char *argv[]) fprintf(stderr, "Built: %s\n", __DATE__); RARCH_LOG_OUTPUT("Version: %s\n", PACKAGE_VERSION); #ifdef HAVE_GIT_VERSION - RARCH_LOG_OUTPUT("Git: %s\n", rarch_git_version); + RARCH_LOG_OUTPUT("Git: %s\n", retroarch_git_version); #endif RARCH_LOG_OUTPUT("=================================================\n"); } - rarch_ctl(RARCH_CTL_VALIDATE_CPU_FEATURES, NULL); + retroarch_validate_cpu_features(); config_load(); runloop_ctl(RUNLOOP_CTL_TASK_INIT, NULL); @@ -1314,18 +1343,15 @@ static int retroarch_main_init(int argc, char *argv[]) rarch_ctl(RARCH_CTL_UNSET_ERROR_ON_INIT, NULL); rarch_ctl(RARCH_CTL_SET_INITED, NULL); - return 0; + + return true; error: command_event(CMD_EVENT_CORE_DEINIT, NULL); rarch_ctl(RARCH_CTL_UNSET_INITED, NULL); - return 1; + return false; } -#define FAIL_CPU(simd_type) do { \ - RARCH_ERR(simd_type " code is compiled in, but CPU does not support this feature. Cannot continue.\n"); \ - retroarch_fail(1, "validate_cpu_features()"); \ -} while(0) bool rarch_ctl(enum rarch_ctl_state state, void *data) { @@ -1339,20 +1365,6 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data) switch(state) { - case RARCH_CTL_SET_PATHS: - retroarch_set_basename((const char*)data); - - if (!global->has_set.save_path) - fill_pathname_noext(global->name.savefile, global->name.base, - ".srm", sizeof(global->name.savefile)); - if (!global->has_set.state_path) - fill_pathname_noext(global->name.savestate, global->name.base, - ".state", sizeof(global->name.savestate)); - fill_pathname_noext(global->name.cheatfile, global->name.base, - ".cht", sizeof(global->name.cheatfile)); - - retroarch_set_paths_redirect((const char*)data); - break; case RARCH_CTL_IS_PLAIN_CORE: return (current_core_type == CORE_TYPE_PLAIN); case RARCH_CTL_IS_DUMMY_CORE: @@ -1429,13 +1441,6 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data) rarch_ctl(RARCH_CTL_UNSET_INITED, NULL); break; - case RARCH_CTL_MAIN_INIT: - { - struct rarch_main_wrap *wrap = (struct rarch_main_wrap*)data; - if (retroarch_main_init(wrap->argc, wrap->argv)) - return false; - } - break; case RARCH_CTL_INIT: rarch_ctl(RARCH_CTL_DEINIT, NULL); retroarch_init_state(); @@ -1482,29 +1487,6 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data) break; case RARCH_CTL_IS_BLOCK_CONFIG_READ: return rarch_block_config_read; - case RARCH_CTL_REPLACE_CONFIG: - { - char *path = (char*)data; - - if (!path) - return false; - - /* If config file to be replaced is the same as the - * current config file, exit. */ - if (string_is_equal(path, global->path.config)) - return false; - - if (settings->config_save_on_exit && *global->path.config) - config_save_file(global->path.config); - - strlcpy(global->path.config, path, sizeof(global->path.config)); - - rarch_ctl(RARCH_CTL_UNSET_BLOCK_CONFIG_READ, NULL); - - *settings->path.libretro = '\0'; /* Load core in new config. */ - } - runloop_ctl(RUNLOOP_CTL_PREPARE_DUMMY, NULL); - break; case RARCH_CTL_MENU_RUNNING: #ifdef HAVE_MENU menu_driver_ctl(RARCH_MENU_CTL_SET_TOGGLE, NULL); @@ -1512,18 +1494,6 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data) #ifdef HAVE_OVERLAY if (settings->input.overlay_hide_in_menu) command_event(CMD_EVENT_OVERLAY_DEINIT, NULL); -#endif - break; - case RARCH_CTL_LOAD_CONTENT: - case RARCH_CTL_LOAD_CONTENT_FFMPEG: - case RARCH_CTL_LOAD_CONTENT_IMAGEVIEWER: -#ifdef HAVE_MENU - /* If content loading fails, we go back to menu. */ - if (!menu_content_ctl(MENU_CONTENT_CTL_LOAD, NULL)) - { - rarch_ctl(RARCH_CTL_MENU_RUNNING, NULL); - return false; - } #endif break; case RARCH_CTL_MENU_RUNNING_FINISHED: @@ -1536,49 +1506,6 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data) command_event(CMD_EVENT_OVERLAY_INIT, NULL); #endif break; - case RARCH_CTL_QUIT: - runloop_ctl(RUNLOOP_CTL_SET_SHUTDOWN, NULL); - rarch_ctl(RARCH_CTL_MENU_RUNNING_FINISHED, NULL); - break; - case RARCH_CTL_FORCE_QUIT: - rarch_ctl(RARCH_CTL_QUIT, NULL); - break; - case RARCH_CTL_VALIDATE_CPU_FEATURES: - { - uint64_t cpu = cpu_features_get(); - (void)cpu; - -#ifdef __SSE__ - if (!(cpu & RETRO_SIMD_SSE)) - FAIL_CPU("SSE"); -#endif -#ifdef __SSE2__ - if (!(cpu & RETRO_SIMD_SSE2)) - FAIL_CPU("SSE2"); -#endif -#ifdef __AVX__ - if (!(cpu & RETRO_SIMD_AVX)) - FAIL_CPU("AVX"); -#endif - } - break; - case RARCH_CTL_FILL_PATHNAMES: - retroarch_init_savefile_paths(); - bsv_movie_set_path(global->name.savefile); - - if (!*global->name.base) - return false; - - if (!*global->name.ups) - fill_pathname_noext(global->name.ups, global->name.base, ".ups", - sizeof(global->name.ups)); - if (!*global->name.bps) - fill_pathname_noext(global->name.bps, global->name.base, ".bps", - sizeof(global->name.bps)); - if (!*global->name.ips) - fill_pathname_noext(global->name.ips, global->name.base, ".ips", - sizeof(global->name.ips)); - break; case RARCH_CTL_NONE: default: return false; @@ -1587,6 +1514,75 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data) return true; } +/* Replaces currently loaded configuration file with + * another one. Will load a dummy core to flush state + * properly. */ +bool retroarch_replace_config(char *path) +{ + settings_t *settings = config_get_ptr(); + global_t *global = global_get_ptr(); + + if (!path) + return false; + + /* If config file to be replaced is the same as the + * current config file, exit. */ + if (string_is_equal(path, global->path.config)) + return false; + + if (settings->config_save_on_exit && *global->path.config) + config_save_file(global->path.config); + + strlcpy(global->path.config, path, sizeof(global->path.config)); + + rarch_ctl(RARCH_CTL_UNSET_BLOCK_CONFIG_READ, NULL); + + *settings->path.libretro = '\0'; /* Load core in new config. */ + + runloop_prepare_dummy(); + + return true; +} + +void retroarch_set_pathnames(const char *path) +{ + global_t *global = global_get_ptr(); + + retroarch_set_basename(path); + + if (!global->has_set.save_path) + fill_pathname_noext(global->name.savefile, global->name.base, + ".srm", sizeof(global->name.savefile)); + if (!global->has_set.state_path) + fill_pathname_noext(global->name.savestate, global->name.base, + ".state", sizeof(global->name.savestate)); + fill_pathname_noext(global->name.cheatfile, global->name.base, + ".cht", sizeof(global->name.cheatfile)); + + retroarch_set_paths_redirect(path); +} + +void retroarch_fill_pathnames(void) +{ + global_t *global = global_get_ptr(); + + retroarch_init_savefile_paths(); + bsv_movie_set_path(global->name.savefile); + + if (!*global->name.base) + return; + + if (!*global->name.ups) + fill_pathname_noext(global->name.ups, global->name.base, ".ups", + sizeof(global->name.ups)); + if (!*global->name.bps) + fill_pathname_noext(global->name.bps, global->name.base, ".bps", + sizeof(global->name.bps)); + if (!*global->name.ips) + fill_pathname_noext(global->name.ips, global->name.base, ".ips", + sizeof(global->name.ips)); +} + int retroarch_get_capabilities(enum rarch_capabilities type, char *s, size_t len) { @@ -1678,3 +1674,9 @@ void retroarch_fail(int error_code, const char *error) strlcpy(error_string, error, sizeof(error_string)); longjmp(error_sjlj_context, error_code); } + +void retroarch_main_quit(void) +{ + runloop_ctl(RUNLOOP_CTL_SET_SHUTDOWN, NULL); + rarch_ctl(RARCH_CTL_MENU_RUNNING_FINISHED, NULL); +} diff --git a/retroarch.h b/retroarch.h index 253c659105..0ce529bd78 100644 --- a/retroarch.h +++ b/retroarch.h @@ -60,9 +60,6 @@ enum rarch_ctl_state /* Initialize all drivers. */ RARCH_CTL_INIT, - /* Initializes RetroArch. */ - RARCH_CTL_MAIN_INIT, - /* Deinitializes RetroArch. */ RARCH_CTL_MAIN_DEINIT, @@ -80,39 +77,14 @@ enum rarch_ctl_state RARCH_CTL_DESTROY, - RARCH_CTL_LOAD_CONTENT, - - RARCH_CTL_LOAD_CONTENT_FFMPEG, - - RARCH_CTL_LOAD_CONTENT_IMAGEVIEWER, - RARCH_CTL_MENU_RUNNING, RARCH_CTL_MENU_RUNNING_FINISHED, - /* Replaces currently loaded configuration file with - * another one. Will load a dummy core to flush state - * properly. */ - RARCH_CTL_REPLACE_CONFIG, - - RARCH_CTL_QUIT, - - RARCH_CTL_FORCE_QUIT, - - /* Validates CPU features for given processor architecture. - * Make sure we haven't compiled for something we cannot run. - * Ideally, code would get swapped out depending on CPU support, - * but this will do for now. */ - RARCH_CTL_VALIDATE_CPU_FEATURES, - - RARCH_CTL_FILL_PATHNAMES, - RARCH_CTL_SET_PATHS_REDIRECT, RARCH_CTL_SET_SRAM_ENABLE, - RARCH_CTL_SET_PATHS, - RARCH_CTL_SET_FORCE_FULLSCREEN, RARCH_CTL_UNSET_FORCE_FULLSCREEN, @@ -179,6 +151,15 @@ const char *retroarch_get_current_savefile_dir(void); bool retroarch_validate_game_options(char *s, size_t len, bool mkdir); +void retroarch_set_pathnames(const char *path); + +void retroarch_fill_pathnames(void); + +/* Replaces currently loaded configuration file with + * another one. Will load a dummy core to flush state + * properly. */ +bool retroarch_replace_config(char *path); + /** * retroarch_fail: * @error_code : Error code. @@ -188,6 +169,19 @@ bool retroarch_validate_game_options(char *s, size_t len, bool mkdir); **/ void retroarch_fail(int error_code, const char *error); +/** + * retroarch_main_init: + * @argc : Count of (commandline) arguments. + * @argv : (Commandline) arguments. + * + * Initializes the program. + * + * Returns: 1 (true) on success, otherwise false (0) if there was an error. + **/ +bool retroarch_main_init(int argc, char *argv[]); + +void retroarch_main_quit(void); + #ifdef __cplusplus } #endif diff --git a/runloop.c b/runloop.c index 7e42d10147..ce0f8f18a4 100644 --- a/runloop.c +++ b/runloop.c @@ -29,6 +29,7 @@ #endif #include #include +#include #include @@ -38,7 +39,6 @@ #include "autosave.h" #include "core_info.h" #include "configuration.h" -#include "performance.h" #include "movie.h" #include "retroarch.h" #include "runloop.h" @@ -60,6 +60,7 @@ #ifdef HAVE_MENU #include "menu/menu_driver.h" +#include "menu/menu_content.h" #endif #ifdef HAVE_NETPLAY @@ -92,6 +93,12 @@ cmd->state[1], cmd->state[2])) #endif +struct rarch_dir_list +{ + struct string_list *list; + size_t ptr; +}; + typedef struct event_cmd_state { retro_input_t state[3]; @@ -226,6 +233,60 @@ static bool runloop_check_movie_record(void) return true; } +static bool runloop_check_movie_init(void) +{ + char msg[128], path[PATH_MAX_LENGTH]; + settings_t *settings = config_get_ptr(); + if (bsv_movie_ctl(BSV_MOVIE_CTL_IS_INITED, NULL)) + return false; + + settings->rewind_granularity = 1; + + if (settings->state_slot > 0) + snprintf(path, sizeof(path), "%s%d", + bsv_movie_get_path(), settings->state_slot); + else + strlcpy(path, bsv_movie_get_path(), sizeof(path)); + + strlcat(path, ".bsv", sizeof(path)); + + snprintf(msg, sizeof(msg), "%s \"%s\".", + msg_hash_to_str(MSG_STARTING_MOVIE_RECORD_TO), + path); + + bsv_movie_init_handle(path, RARCH_MOVIE_RECORD); + + if (!bsv_movie_ctl(BSV_MOVIE_CTL_IS_INITED, NULL)) + return false; + + if (bsv_movie_ctl(BSV_MOVIE_CTL_IS_INITED, NULL)) + { + runloop_msg_queue_push(msg, 1, 180, true); + RARCH_LOG("%s \"%s\".\n", + msg_hash_to_str(MSG_STARTING_MOVIE_RECORD_TO), + path); + } + else + { + runloop_msg_queue_push( + msg_hash_to_str(MSG_FAILED_TO_START_MOVIE_RECORD), + 1, 180, true); + RARCH_ERR("%s\n", + msg_hash_to_str(MSG_FAILED_TO_START_MOVIE_RECORD)); + } + + return true; +} + +static bool runloop_check_movie(void) +{ + if (bsv_movie_ctl(BSV_MOVIE_CTL_PLAYBACK_ON, NULL)) + return runloop_check_movie_playback(); + if (!bsv_movie_ctl(BSV_MOVIE_CTL_IS_INITED, NULL)) + return runloop_check_movie_init(); + return runloop_check_movie_record(); +} + /* Checks if slowmotion toggle/hold was being pressed and/or held. */ static bool runloop_check_slowmotion(bool *ptr) { @@ -588,7 +649,7 @@ static bool runloop_check_state(event_cmd_state_t *cmd, rarch_dir_list_t *shader runloop_check_slowmotion(&tmp); if (runloop_cmd_triggered(cmd, RARCH_MOVIE_RECORD_TOGGLE)) - runloop_ctl(RUNLOOP_CTL_CHECK_MOVIE, NULL); + runloop_check_movie(); runloop_check_shader_dir(shader_dir, runloop_cmd_triggered(cmd, RARCH_SHADER_NEXT), @@ -659,6 +720,26 @@ static bool runloop_is_frame_count_end(void) } +bool runloop_prepare_dummy(void) +{ + memset(&runloop_frame_time, 0, sizeof(struct retro_frame_time_callback)); +#ifdef HAVE_MENU + menu_driver_ctl(RARCH_MENU_CTL_UNSET_LOAD_NO_CONTENT, NULL); +#endif + runloop_ctl(RUNLOOP_CTL_DATA_DEINIT, NULL); + runloop_ctl(RUNLOOP_CTL_TASK_INIT, NULL); + runloop_ctl(RUNLOOP_CTL_CLEAR_CONTENT_PATH, NULL); + +#ifdef HAVE_MENU + if (!menu_content_ctl(MENU_CONTENT_CTL_LOAD, NULL)) + { + rarch_ctl(RARCH_CTL_MENU_RUNNING, NULL); + return false; + } +#endif + return true; +} + bool runloop_ctl(enum runloop_ctl_state state, void *data) { settings_t *settings = config_get_ptr(); @@ -868,54 +949,6 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data) return false; } break; - case RUNLOOP_CTL_CHECK_MOVIE: - if (bsv_movie_ctl(BSV_MOVIE_CTL_PLAYBACK_ON, NULL)) - return runloop_check_movie_playback(); - if (!bsv_movie_ctl(BSV_MOVIE_CTL_IS_INITED, NULL)) - return runloop_ctl(RUNLOOP_CTL_CHECK_MOVIE_INIT, NULL); - return runloop_check_movie_record(); - case RUNLOOP_CTL_CHECK_MOVIE_INIT: - if (bsv_movie_ctl(BSV_MOVIE_CTL_IS_INITED, NULL)) - return false; - { - char msg[128]; - char path[PATH_MAX_LENGTH]; - - settings->rewind_granularity = 1; - - if (settings->state_slot > 0) - snprintf(path, sizeof(path), "%s%d", - bsv_movie_get_path(), settings->state_slot); - else - strlcpy(path, bsv_movie_get_path(), sizeof(path)); - - strlcat(path, ".bsv", sizeof(path)); - - snprintf(msg, sizeof(msg), "%s \"%s\".", - msg_hash_to_str(MSG_STARTING_MOVIE_RECORD_TO), - path); - - bsv_movie_init_handle(path, RARCH_MOVIE_RECORD); - - if (!bsv_movie_ctl(BSV_MOVIE_CTL_IS_INITED, NULL)) - return false; - else if (bsv_movie_ctl(BSV_MOVIE_CTL_IS_INITED, NULL)) - { - runloop_msg_queue_push(msg, 1, 180, true); - RARCH_LOG("%s \"%s\".\n", - msg_hash_to_str(MSG_STARTING_MOVIE_RECORD_TO), - path); - } - else - { - runloop_msg_queue_push( - msg_hash_to_str(MSG_FAILED_TO_START_MOVIE_RECORD), - 1, 180, true); - RARCH_ERR("%s\n", - msg_hash_to_str(MSG_FAILED_TO_START_MOVIE_RECORD)); - } - } - break; case RUNLOOP_CTL_FRAME_TIME_FREE: memset(&runloop_frame_time, 0, sizeof(struct retro_frame_time_callback)); runloop_frame_time_last = 0; @@ -1043,17 +1076,6 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data) task_queue_ctl(TASK_QUEUE_CTL_INIT, &threaded_enable); } break; - case RUNLOOP_CTL_PREPARE_DUMMY: - memset(&runloop_frame_time, 0, sizeof(struct retro_frame_time_callback)); -#ifdef HAVE_MENU - menu_driver_ctl(RARCH_MENU_CTL_UNSET_LOAD_NO_CONTENT, NULL); -#endif - runloop_ctl(RUNLOOP_CTL_DATA_DEINIT, NULL); - runloop_ctl(RUNLOOP_CTL_TASK_INIT, NULL); - runloop_ctl(RUNLOOP_CTL_CLEAR_CONTENT_PATH, NULL); - - rarch_ctl(RARCH_CTL_LOAD_CONTENT, NULL); - break; case RUNLOOP_CTL_SET_CORE_SHUTDOWN: runloop_core_shutdown_initiated = true; break; @@ -1243,7 +1265,7 @@ static void runloop_iterate_linefeed_overlay(settings_t *settings) * Aborts core shutdown if invoked. */ static int runloop_iterate_time_to_exit_load_dummy(void) { - if (!runloop_ctl(RUNLOOP_CTL_PREPARE_DUMMY, NULL)) + if (!runloop_prepare_dummy()) return -1; runloop_ctl(RUNLOOP_CTL_UNSET_SHUTDOWN, NULL); diff --git a/runloop.h b/runloop.h index 46a74d6e9f..3c7f5ad9b6 100644 --- a/runloop.h +++ b/runloop.h @@ -79,10 +79,6 @@ enum runloop_ctl_state RUNLOOP_CTL_KEY_EVENT_GET, RUNLOOP_CTL_DATA_DEINIT, - RUNLOOP_CTL_CHECK_MOVIE, - - RUNLOOP_CTL_CHECK_MOVIE_INIT, - /* Initializes message queue. */ RUNLOOP_CTL_MSG_QUEUE_INIT, @@ -106,17 +102,12 @@ enum runloop_ctl_state RUNLOOP_CTL_SHADER_DIR_INIT, RUNLOOP_CTL_SYSTEM_INFO_GET, RUNLOOP_CTL_SYSTEM_INFO_INIT, - RUNLOOP_CTL_SYSTEM_INFO_FREE, - RUNLOOP_CTL_PREPARE_DUMMY + RUNLOOP_CTL_SYSTEM_INFO_FREE }; typedef int (*transfer_cb_t)(void *data, size_t len); -typedef struct rarch_dir_list -{ - struct string_list *list; - size_t ptr; -} rarch_dir_list_t; +typedef struct rarch_dir_list rarch_dir_list_t; typedef struct rarch_dir { @@ -127,7 +118,6 @@ typedef struct rarch_dir #ifdef HAVE_OVERLAY char osk_overlay[PATH_MAX_LENGTH]; #endif - rarch_dir_list_t filter_dir; } rarch_dir_t; typedef struct rarch_path @@ -304,6 +294,8 @@ void runloop_msg_queue_push(const char *msg, unsigned prio, char* runloop_msg_queue_pull(void); +bool runloop_prepare_dummy(void); + bool runloop_ctl(enum runloop_ctl_state state, void *data); diff --git a/system.h b/system.h index ad7f656789..96b4ed00da 100644 --- a/system.h +++ b/system.h @@ -17,9 +17,9 @@ #define __RARCH_SYSTEM_H #include +#include #include "driver.h" -#include "libretro.h" #ifndef MAX_USERS #define MAX_USERS 16 diff --git a/tasks/task_image.c b/tasks/task_image.c index 7ae06bfa25..d5fe2c0bea 100644 --- a/tasks/task_image.c +++ b/tasks/task_image.c @@ -27,6 +27,9 @@ #ifdef HAVE_RPNG #include #endif +#ifdef HAVE_RJPEG +#include +#endif #ifdef HAVE_MENU #include "../menu/menu_driver.h" @@ -71,18 +74,6 @@ static int cb_image_menu_upload_generic(void *data, size_t len) return 0; } -static int rarch_main_data_image_iterate_process_transfer_parse( - nbio_handle_t *nbio) -{ - if (nbio->image.handle && nbio->image.cb) - { - size_t len = 0; - nbio->image.cb(nbio, len); - } - - return 0; -} - static int rarch_main_data_image_iterate_transfer_parse(nbio_handle_t *nbio) { if (nbio->image.handle && nbio->image.cb) @@ -108,38 +99,83 @@ static int cb_nbio_default(void *data, size_t len) return 0; } +static int image_transfer_process( + void *data, + enum image_type_enum type, + uint32_t **buf, + unsigned *width, unsigned *height) +{ + switch (type) + { + case IMAGE_TYPE_PNG: +#ifdef HAVE_RPNG + if (!rpng_is_valid((rpng_t*)data)) + return IMAGE_PROCESS_ERROR; + + return rpng_nbio_load_image_argb_process( + (rpng_t*)data, + buf, + width, height); +#endif + break; + case IMAGE_TYPE_JPEG: +#ifdef HAVE_RJPEG +#endif + break; + } + + return 0; +} + +static bool image_transfer_iterate(void *data, enum image_type_enum type) +{ + switch (type) + { + case IMAGE_TYPE_PNG: +#ifdef HAVE_RPNG + if (!rpng_nbio_load_image_argb_iterate((rpng_t*)data)) + return false; +#endif + break; + case IMAGE_TYPE_JPEG: +#ifdef HAVE_RJPEG +#endif + break; + } + + return true; +} + static int rarch_main_data_image_process( nbio_handle_t *nbio, unsigned *width, - unsigned *height, - int *retval) + unsigned *height) { -#ifdef HAVE_RPNG - if (!rpng_is_valid((rpng_t*)nbio->image.handle)) - return IMAGE_PROCESS_ERROR; - - *retval = rpng_nbio_load_image_argb_process( + int retval = image_transfer_process( (rpng_t*)nbio->image.handle, - &nbio->image.ti.pixels, - width, height); -#endif + nbio->image_type, + &nbio->image.ti.pixels, width, height); + + if (retval == IMAGE_PROCESS_ERROR) + return IMAGE_PROCESS_ERROR; nbio->image.ti.width = *width; nbio->image.ti.height = *height; - return *retval; + return retval; } -#ifdef HAVE_RPNG -static int cb_image_menu_generic_rpng(nbio_handle_t *nbio) +static int cb_image_menu_generic(nbio_handle_t *nbio) { int retval = 0; unsigned width = 0, height = 0; if (!nbio) return -1; - switch (rarch_main_data_image_process(nbio, - &width, &height, &retval)) + retval = rarch_main_data_image_process(nbio, + &width, &height); + + switch (retval) { case IMAGE_PROCESS_ERROR: case IMAGE_PROCESS_ERROR_END: @@ -154,23 +190,11 @@ static int cb_image_menu_generic_rpng(nbio_handle_t *nbio) return 0; } -static int cb_image_menu_wallpaper_rpng(void *data, size_t len) -{ - nbio_handle_t *nbio = (nbio_handle_t*)data; - - if (cb_image_menu_generic_rpng(nbio) != 0) - return -1; - - nbio->image.cb = &cb_image_menu_upload_generic; - - return 0; -} - static int cb_image_menu_thumbnail(void *data, size_t len) { nbio_handle_t *nbio = (nbio_handle_t*)data; - if (cb_image_menu_generic_rpng(nbio) != 0) + if (cb_image_menu_generic(nbio) != 0) return -1; nbio->image.cb = &cb_image_menu_upload_generic; @@ -178,31 +202,6 @@ static int cb_image_menu_thumbnail(void *data, size_t len) return 0; } -static int rarch_main_data_image_iterate_transfer(nbio_handle_t *nbio) -{ - unsigned i; - - if (!nbio) - return -1; - - if (nbio->image.is_finished) - return 0; - - for (i = 0; i < nbio->image.pos_increment; i++) - { - /* TODO/FIXME - add JPEG equivalents as well */ - if (!rpng_nbio_load_image_argb_iterate((rpng_t*)nbio->image.handle)) - goto error; - } - - nbio->image.frame_count++; - return 0; - -error: - return -1; -} - - static int rarch_main_data_image_iterate_process_transfer(nbio_handle_t *nbio) { unsigned i, width = 0, height = 0; @@ -213,8 +212,9 @@ static int rarch_main_data_image_iterate_process_transfer(nbio_handle_t *nbio) for (i = 0; i < nbio->image.processing_pos_increment; i++) { - if (rarch_main_data_image_process(nbio, - &width, &height, &retval) != IMAGE_PROCESS_NEXT) + retval = rarch_main_data_image_process(nbio, + &width, &height); + if (retval != IMAGE_PROCESS_NEXT) break; } @@ -225,21 +225,53 @@ static int rarch_main_data_image_iterate_process_transfer(nbio_handle_t *nbio) return -1; } + +static int rarch_main_data_image_iterate_transfer(nbio_handle_t *nbio) +{ + unsigned i; + + if (!nbio) + goto error; + + if (nbio->image.is_finished) + return 0; + + for (i = 0; i < nbio->image.pos_increment; i++) + { + if (!image_transfer_iterate(nbio->image.handle, nbio->image_type)) + goto error; + } + + nbio->image.frame_count++; + return 0; + +error: + return -1; +} + static void rarch_task_image_load_free_internal(nbio_handle_t *nbio) { nbio_image_handle_t *image = nbio ? &nbio->image : NULL; + switch (nbio->image_type) + { + case IMAGE_TYPE_PNG: #ifdef HAVE_RPNG - /* TODO/FIXME - add JPEG equivalents as well */ - rpng_nbio_load_image_free((rpng_t*)image->handle); + rpng_nbio_load_image_free((rpng_t*)image->handle); #endif + break; + case IMAGE_TYPE_JPEG: +#ifdef HAVE_RJPEG +#endif + break; + } image->handle = NULL; image->cb = NULL; image->frame_count = 0; } -static int cb_nbio_generic_rpng(nbio_handle_t *nbio, size_t *len) +static int cb_nbio_generic(nbio_handle_t *nbio, size_t *len) { void *ptr = NULL; @@ -251,12 +283,35 @@ static int cb_nbio_generic_rpng(nbio_handle_t *nbio, size_t *len) if (!ptr) goto error; - rpng_set_buf_ptr((rpng_t*)nbio->image.handle, (uint8_t*)ptr); + switch (nbio->image_type) + { + case IMAGE_TYPE_PNG: +#ifdef HAVE_RPNG + rpng_set_buf_ptr((rpng_t*)nbio->image.handle, (uint8_t*)ptr); +#endif + break; + case IMAGE_TYPE_JPEG: +#ifdef HAVE_RJPEG +#endif + break; + } + nbio->image.pos_increment = (*len / 2) ? (*len / 2) : 1; nbio->image.processing_pos_increment = (*len / 4) ? (*len / 4) : 1; - if (!rpng_nbio_load_image_argb_start((rpng_t*)nbio->image.handle)) - goto error; + switch (nbio->image_type) + { + case IMAGE_TYPE_PNG: +#ifdef HAVE_RPNG + if (!rpng_nbio_load_image_argb_start((rpng_t*)nbio->image.handle)) + goto error; +#endif + break; + case IMAGE_TYPE_JPEG: +#ifdef HAVE_RJPEG +#endif + break; + } nbio->image.is_blocking = false; nbio->image.is_finished = false; @@ -269,32 +324,30 @@ error: return -1; } -static int cb_nbio_image_menu_wallpaper_rpng(void *data, size_t len) +static int cb_nbio_image_menu_thumbnail(void *data, size_t len) { nbio_handle_t *nbio = (nbio_handle_t*)data; if (!nbio || !data) return -1; - nbio->image.handle = rpng_alloc(); - nbio->image.cb = &cb_image_menu_wallpaper_rpng; + switch (nbio->image_type) + { + case IMAGE_TYPE_PNG: +#ifdef HAVE_RPNG + nbio->image.handle = rpng_alloc(); +#endif + break; + case IMAGE_TYPE_JPEG: +#ifdef HAVE_RJPEG +#endif + break; + } - return cb_nbio_generic_rpng(nbio, &len); -} - -static int cb_nbio_image_menu_thumbnail_rpng(void *data, size_t len) -{ - nbio_handle_t *nbio = (nbio_handle_t*)data; - - if (!nbio || !data) - return -1; - - nbio->image.handle = rpng_alloc(); nbio->image.cb = &cb_image_menu_thumbnail; - return cb_nbio_generic_rpng(nbio, &len); + return cb_nbio_generic(nbio, &len); } -#endif bool rarch_task_image_load_handler(retro_task_t *task) { @@ -318,7 +371,7 @@ bool rarch_task_image_load_handler(retro_task_t *task) image->status = IMAGE_STATUS_TRANSFER_PARSE; break; case IMAGE_STATUS_PROCESS_TRANSFER_PARSE: - rarch_main_data_image_iterate_process_transfer_parse(nbio); + rarch_main_data_image_iterate_transfer_parse(nbio); if (!image->is_finished) break; case IMAGE_STATUS_TRANSFER_PARSE_FREE: @@ -365,17 +418,18 @@ bool rarch_task_push_image_load(const char *fullpath, nbio->image.status = IMAGE_STATUS_TRANSFER; if (strstr(fullpath, ".png")) - { -#ifdef HAVE_RPNG - if (cb_type_hash == CB_MENU_WALLPAPER) - nbio->cb = &cb_nbio_image_menu_wallpaper_rpng; - else if (cb_type_hash == CB_MENU_THUMBNAIL) - nbio->cb = &cb_nbio_image_menu_thumbnail_rpng; -#endif - } + nbio->image_type = IMAGE_TYPE_PNG; else if (strstr(fullpath, ".jpeg") || strstr(fullpath, ".jpg")) + nbio->image_type = IMAGE_TYPE_JPEG; + + switch (cb_type_hash) { - /* TODO/FIXME */ + case CB_MENU_WALLPAPER: + case CB_MENU_THUMBNAIL: + nbio->cb = &cb_nbio_image_menu_thumbnail; + break; + default: + break; } nbio_begin_read(handle); diff --git a/tasks/tasks_internal.h b/tasks/tasks_internal.h index 897ce2fc2f..f880dbe156 100644 --- a/tasks/tasks_internal.h +++ b/tasks/tasks_internal.h @@ -40,8 +40,15 @@ enum nbio_status_enum NBIO_STATUS_TRANSFER_PARSE_FREE }; +enum image_type_enum +{ + IMAGE_TYPE_PNG = 0, + IMAGE_TYPE_JPEG +}; + #ifdef HAVE_NETWORKING -typedef struct { +typedef struct +{ char *data; size_t len; } http_transfer_data_t; @@ -51,6 +58,7 @@ typedef struct http_transfer_info char url[PATH_MAX_LENGTH]; int progress; } http_transfer_info_t; +#endif typedef struct nbio_image_handle { @@ -69,6 +77,7 @@ typedef struct nbio_image_handle typedef struct nbio_handle { + enum image_type_enum image_type; nbio_image_handle_t image; bool is_finished; transfer_cb_t cb; @@ -79,6 +88,7 @@ typedef struct nbio_handle unsigned status; } nbio_handle_t; +#ifdef HAVE_NETWORKING void *rarch_task_push_http_transfer(const char *url, const char *type, retro_task_callback_t cb, void *userdata); @@ -131,7 +141,7 @@ bool rarch_task_push_content_load_default( void rarch_task_image_load_free(retro_task_t *task); -void rarch_task_file_load_handler(retro_task_t *task);; +void rarch_task_file_load_handler(retro_task_t *task); #ifdef __cplusplus } diff --git a/ui/drivers/ui_cocoatouch.m b/ui/drivers/ui_cocoatouch.m index 586dada58a..aae07ab0e0 100644 --- a/ui/drivers/ui_cocoatouch.m +++ b/ui/drivers/ui_cocoatouch.m @@ -337,9 +337,6 @@ enum apple_platform = self; [self setDelegate:self]; - - if (rarch_main(argc, argv, NULL)) - apple_rarch_exited(); #ifdef HAVE_AVFOUNDATION /* Other background audio check */