From 6b466c601357b19c2da0b8fb25de1efe845a92f7 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 9 Jul 2020 07:46:40 +0200 Subject: [PATCH] Cleanups --- frontend/drivers/platform_emscripten.c | 42 +-------------------- gfx/drivers/gdi_gfx.c | 2 +- gfx/drivers/gl.c | 9 ++--- gfx/drivers/gl1.c | 8 ++-- gfx/drivers/gl_core.c | 9 ++--- gfx/drivers/vg.c | 4 +- gfx/drivers/vulkan.c | 9 ++--- retroarch.c | 51 ++++++++++++++++++++++++-- retroarch.h | 3 -- 9 files changed, 68 insertions(+), 69 deletions(-) diff --git a/frontend/drivers/platform_emscripten.c b/frontend/drivers/platform_emscripten.c index 1890205207..f9f2dad817 100644 --- a/frontend/drivers/platform_emscripten.c +++ b/frontend/drivers/platform_emscripten.c @@ -46,48 +46,8 @@ #include "../../tasks/tasks_internal.h" #include "../../file_path_special.h" -void RWebAudioRecalibrateTime(void); void dummyErrnoCodes(void); - -static unsigned emscripten_frame_count = 0; - -static void emscripten_mainloop(void) -{ - int ret; - video_frame_info_t video_info; - - RWebAudioRecalibrateTime(); - - emscripten_frame_count++; - - video_driver_build_info(&video_info); - - /* Disable BFI during fast forward, slow-motion, - * and pause to prevent flicker. */ - if ( - video_info.black_frame_insertion - && !video_info.input_driver_nonblock_state - && !video_info.runloop_is_slowmotion - && !video_info.runloop_is_paused) - { - if ((emscripten_frame_count & 1) == 0) - { - glClear(GL_COLOR_BUFFER_BIT); - video_info.cb_swap_buffers(video_info.context_data); - return; - } - } - - ret = runloop_iterate(); - - task_queue_check(); - - if (ret != -1) - return; - - main_exit(NULL); - emscripten_force_exit(0); -} +void emscripten_mainloop(void); void cmd_savefiles(void) { diff --git a/gfx/drivers/gdi_gfx.c b/gfx/drivers/gdi_gfx.c index 2996ade4f4..eb311b4d15 100644 --- a/gfx/drivers/gdi_gfx.c +++ b/gfx/drivers/gdi_gfx.c @@ -352,7 +352,7 @@ static bool gdi_gfx_frame(void *data, const void *frame, if (gdi->ctx_driver->update_window_title) gdi->ctx_driver->update_window_title( - video_info->context_data); + gdi->ctx_data); return true; } diff --git a/gfx/drivers/gl.c b/gfx/drivers/gl.c index fdadbd3077..02db144cfe 100644 --- a/gfx/drivers/gl.c +++ b/gfx/drivers/gl.c @@ -2829,7 +2829,6 @@ static bool gl2_frame(void *data, const void *frame, bool runloop_is_paused = video_info->runloop_is_paused; bool hard_sync = video_info->hard_sync; unsigned hard_sync_frames = video_info->hard_sync_frames; - void *context_data = video_info->context_data; struct font_params *osd_params = (struct font_params*) &video_info->osd_stat_params; const char *stat_text = video_info->stat_text; @@ -2866,7 +2865,7 @@ static bool gl2_frame(void *data, const void *frame, if (gl->should_resize) { if (gl->ctx_driver->set_resize) - gl->ctx_driver->set_resize(context_data, + gl->ctx_driver->set_resize(gl->ctx_data, width, height); gl->should_resize = false; @@ -3073,7 +3072,7 @@ static bool gl2_frame(void *data, const void *frame, } if (gl->ctx_driver->update_window_title) - gl->ctx_driver->update_window_title(context_data); + gl->ctx_driver->update_window_title(gl->ctx_data); /* Reset state which could easily mess up libretro core. */ if (gl->hw_render_fbo_init) @@ -3108,13 +3107,13 @@ static bool gl2_frame(void *data, const void *frame, && !runloop_is_paused) { if (gl->ctx_driver->swap_buffers) - gl->ctx_driver->swap_buffers(context_data); + gl->ctx_driver->swap_buffers(gl->ctx_data); glClear(GL_COLOR_BUFFER_BIT); } #endif if (gl->ctx_driver->swap_buffers) - gl->ctx_driver->swap_buffers(context_data); + gl->ctx_driver->swap_buffers(gl->ctx_data); /* check if we are fast forwarding or in menu, if we are ignore hard sync */ if ( gl->have_sync diff --git a/gfx/drivers/gl1.c b/gfx/drivers/gl1.c index bb956ec74c..c8299a38f4 100644 --- a/gfx/drivers/gl1.c +++ b/gfx/drivers/gl1.c @@ -721,7 +721,7 @@ static bool gl1_gfx_frame(void *data, const void *frame, mode.height = height; if (gl1->ctx_driver->set_resize) - gl1->ctx_driver->set_resize(video_info->context_data, + gl1->ctx_driver->set_resize(gl1->ctx_data, mode.width, mode.height); gl1_gfx_set_viewport(gl1, @@ -881,7 +881,7 @@ static bool gl1_gfx_frame(void *data, const void *frame, if (gl1->ctx_driver->update_window_title) gl1->ctx_driver->update_window_title( - video_info->context_data); + gl1->ctx_data); /* Screenshots. */ if (gl1->readback_buffer_screenshot) @@ -899,12 +899,12 @@ static bool gl1_gfx_frame(void *data, const void *frame, && !video_info->runloop_is_slowmotion && !video_info->runloop_is_paused) { - gl1->ctx_driver->swap_buffers(video_info->context_data); + gl1->ctx_driver->swap_buffers(gl1->ctx_data); glClear(GL_COLOR_BUFFER_BIT); } #endif - gl1->ctx_driver->swap_buffers(video_info->context_data); + gl1->ctx_driver->swap_buffers(gl1->ctx_data); /* check if we are fast forwarding or in menu, if we are ignore hard sync */ if (video_info->hard_sync diff --git a/gfx/drivers/gl_core.c b/gfx/drivers/gl_core.c index e426a3cb18..e288472aa2 100644 --- a/gfx/drivers/gl_core.c +++ b/gfx/drivers/gl_core.c @@ -1847,7 +1847,6 @@ static bool gl_core_frame(void *data, const void *frame, bool statistics_show = video_info->statistics_show; bool msg_bgcolor_enable = video_info->msg_bgcolor_enable; bool black_frame_insertion = video_info->black_frame_insertion; - void *context_data = video_info->context_data; unsigned hard_sync_frames = video_info->hard_sync_frames; bool runloop_is_paused = video_info->runloop_is_paused; bool runloop_is_slowmotion = video_info->runloop_is_slowmotion; @@ -1878,7 +1877,7 @@ static bool gl_core_frame(void *data, const void *frame, if (gl->should_resize) { if (gl->ctx_driver->set_resize) - gl->ctx_driver->set_resize(context_data, + gl->ctx_driver->set_resize(gl->ctx_data, width, height); gl->should_resize = false; } @@ -1961,7 +1960,7 @@ static bool gl_core_frame(void *data, const void *frame, } if (gl->ctx_driver->update_window_title) - gl->ctx_driver->update_window_title(context_data); + gl->ctx_driver->update_window_title(gl->ctx_data); if (gl->readback_buffer_screenshot) { @@ -1985,11 +1984,11 @@ static bool gl_core_frame(void *data, const void *frame, && !runloop_is_slowmotion && !runloop_is_paused) { - gl->ctx_driver->swap_buffers(context_data); + gl->ctx_driver->swap_buffers(gl->ctx_data); glClear(GL_COLOR_BUFFER_BIT); } - gl->ctx_driver->swap_buffers(context_data); + gl->ctx_driver->swap_buffers(gl->ctx_data); if (video_info->hard_sync && !input_driver_nonblock_state && diff --git a/gfx/drivers/vg.c b/gfx/drivers/vg.c index dd3aa6906d..c4d0e4289b 100644 --- a/gfx/drivers/vg.c +++ b/gfx/drivers/vg.c @@ -456,9 +456,9 @@ static bool vg_frame(void *data, const void *frame, #endif if (vg->ctx_driver->update_window_title) - vg->ctx_driver->update_window_title(video_info->context_data); + vg->ctx_driver->update_window_title(vg->ctx_data); - vg->ctx_driver->swap_buffers(video_info->context_data); + vg->ctx_driver->swap_buffers(vg->ctx_data); return true; } diff --git a/gfx/drivers/vulkan.c b/gfx/drivers/vulkan.c index fec29e856c..73459197c4 100644 --- a/gfx/drivers/vulkan.c +++ b/gfx/drivers/vulkan.c @@ -1716,7 +1716,6 @@ static bool vulkan_frame(void *data, const void *frame, bool waits_for_semaphores = false; unsigned width = video_info->width; unsigned height = video_info->height; - void *context_data = video_info->context_data; bool statistics_show = video_info->statistics_show; const char *stat_text = video_info->stat_text; bool black_frame_insertion = video_info->black_frame_insertion; @@ -2225,12 +2224,12 @@ static bool vulkan_frame(void *data, const void *frame, slock_unlock(vk->context->queue_lock); #endif - vk->ctx_driver->swap_buffers(context_data); + vk->ctx_driver->swap_buffers(vk->ctx_data); if (!vk->context->swap_interval_emulation_lock) { if (vk->ctx_driver->update_window_title) - vk->ctx_driver->update_window_title(context_data); + vk->ctx_driver->update_window_title(vk->ctx_data); } /* Handle spurious swapchain invalidations as soon as we can, @@ -2242,7 +2241,7 @@ static bool vulkan_frame(void *data, const void *frame, mode.height = height; if (vk->ctx_driver->set_resize) - vk->ctx_driver->set_resize(context_data, mode.width, mode.height); + vk->ctx_driver->set_resize(vk->ctx_data, mode.width, mode.height); vk->should_resize = false; } @@ -2258,7 +2257,7 @@ static bool vulkan_frame(void *data, const void *frame, && !input_driver_nonblock_state && !runloop_is_slowmotion && !runloop_is_paused) - vulkan_inject_black_frame(vk, video_info, context_data); + vulkan_inject_black_frame(vk, video_info, vk->ctx_data); /* Vulkan doesn't directly support swap_interval > 1, * so we fake it by duping out more frames. */ diff --git a/retroarch.c b/retroarch.c index 06d5198b16..3c1643793c 100644 --- a/retroarch.c +++ b/retroarch.c @@ -17244,6 +17244,54 @@ int rarch_main(int argc, char *argv[], void *data) return 0; } +#if defined(EMSCRIPTEN) +void RWebAudioRecalibrateTime(void); + +void emscripten_mainloop(void) +{ + int ret; + static unsigned emscripten_frame_count = 0; + struct rarch_state *p_rarch = &rarch_st; + settings_t *settings = p_rarch->configuration_settings; + bool black_frame_insertion = settings->bools.video_black_frame_insertion; + bool input_driver_nonblock_state = p_rarch->input_driver_nonblock_state; + bool runloop_is_slowmotion = p_rarch->runloop_slowmotion; + bool runloop_is_paused = p_rarch->runloop_paused; + + RWebAudioRecalibrateTime(); + + emscripten_frame_count++; + + /* Disable BFI during fast forward, slow-motion, + * and pause to prevent flicker. */ + if ( + black_frame_insertion + && !input_driver_nonblock_state + && !runloop_is_slowmotion + && !runloop_is_paused) + { + if ((emscripten_frame_count & 1) == 0) + { + glClear(GL_COLOR_BUFFER_BIT); + if (p_rarch->current_video_context.swap_buffers) + p_rarch->current_video_context.swap_buffers( + p_rarch->video_context_data); + return; + } + } + + ret = runloop_iterate(); + + task_queue_check(); + + if (ret != -1) + return; + + main_exit(NULL); + emscripten_force_exit(0); +} +#endif + #ifndef HAVE_MAIN #ifdef __cplusplus extern "C" @@ -32692,9 +32740,6 @@ void video_driver_build_info(video_frame_info_t *video_info) video_info->runloop_is_slowmotion = p_rarch->runloop_slowmotion; video_info->input_driver_nonblock_state = p_rarch->input_driver_nonblock_state; - video_info->context_data = p_rarch->video_context_data; - video_info->cb_swap_buffers = p_rarch->current_video_context.swap_buffers; - video_info->userdata = VIDEO_DRIVER_GET_PTR_INTERNAL(false); #ifdef HAVE_THREADS diff --git a/retroarch.h b/retroarch.h index e6a25478c5..6e5bdac0fa 100644 --- a/retroarch.h +++ b/retroarch.h @@ -1197,9 +1197,6 @@ typedef struct video_frame_info enum text_alignment text_align; } osd_stat_params; - void (*cb_swap_buffers)(void*); - - void *context_data; void *userdata; } video_frame_info_t;