diff --git a/command_event.c b/command_event.c index c05447ed7c..385cb4dba1 100644 --- a/command_event.c +++ b/command_event.c @@ -1199,9 +1199,6 @@ bool event_command(enum event_command cmd) #endif break; case EVENT_CMD_DSP_FILTER_DEINIT: - if (!global) - break; - audio_driver_dsp_filter_free(); break; case EVENT_CMD_DSP_FILTER_INIT: @@ -1211,12 +1208,7 @@ bool event_command(enum event_command cmd) audio_driver_dsp_filter_init(settings->audio.dsp_plugin); break; case EVENT_CMD_GPU_RECORD_DEINIT: - if (!global) - break; - - if (global->record.gpu_buffer) - free(global->record.gpu_buffer); - global->record.gpu_buffer = NULL; + video_driver_ctl(RARCH_DISPLAY_CTL_GPU_RECORD_DEINIT, NULL); break; case EVENT_CMD_RECORD_DEINIT: if (!recording_deinit()) diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 6c7ad00078..9f8e0b73d3 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -1395,6 +1395,7 @@ bool video_driver_ctl(enum rarch_display_ctl_state state, void *data) settings_t *settings = config_get_ptr(); const struct retro_hw_render_callback *hw_render = (const struct retro_hw_render_callback*)video_driver_callback(); + static uint8_t *video_driver_record_gpu_buffer = NULL; switch (state) { @@ -1661,6 +1662,33 @@ bool video_driver_ctl(enum rarch_display_ctl_state state, void *data) break; case RARCH_DISPLAY_CTL_IS_ACTIVE: return video_driver_active; + case RARCH_DISPLAY_CTL_HAS_GPU_RECORD: + return (video_driver_record_gpu_buffer != NULL); + case RARCH_DISPLAY_CTL_GPU_RECORD_GET: + { + uint8_t **new_data = (uint8_t**)data; + + if (!new_data) + return false; + *new_data = video_driver_record_gpu_buffer; + return true; + } + break; + case RARCH_DISPLAY_CTL_GPU_RECORD_INIT: + { + unsigned *new_size = (unsigned*)data; + if (!new_size) + return false; + video_driver_record_gpu_buffer = (uint8_t*)malloc(*new_size); + if (!video_driver_record_gpu_buffer) + return false; + return true; + } + case RARCH_DISPLAY_CTL_GPU_RECORD_DEINIT: + if (video_driver_record_gpu_buffer) + free(video_driver_record_gpu_buffer); + video_driver_record_gpu_buffer = NULL; + break; case RARCH_DISPLAY_CTL_NONE: default: break; @@ -1820,7 +1848,6 @@ void video_driver_frame(const void *data, unsigned width, unsigned output_height = 0; unsigned output_pitch = 0; const char *msg = NULL; - global_t *global = global_get_ptr(); settings_t *settings = config_get_ptr(); if (!video_driver_ctl(RARCH_DISPLAY_CTL_IS_ACTIVE, NULL)) @@ -1844,7 +1871,7 @@ void video_driver_frame(const void *data, unsigned width, !video_driver_state.filter.filter || !settings->video.post_filter_record || !data - || (global && global->record.gpu_buffer) + || video_driver_ctl(RARCH_DISPLAY_CTL_HAS_GPU_RECORD, NULL) ) ) recording_dump_frame(data, width, height, pitch); diff --git a/gfx/video_driver.h b/gfx/video_driver.h index acb63477b7..74f2c31834 100644 --- a/gfx/video_driver.h +++ b/gfx/video_driver.h @@ -145,7 +145,11 @@ enum rarch_display_ctl_state RARCH_DISPLAY_CTL_IS_VIDEO_CACHE_CONTEXT_ACK, RARCH_DISPLAY_CTL_SET_ACTIVE, RARCH_DISPLAY_CTL_UNSET_ACTIVE, - RARCH_DISPLAY_CTL_IS_ACTIVE + RARCH_DISPLAY_CTL_IS_ACTIVE, + RARCH_DISPLAY_CTL_HAS_GPU_RECORD, + RARCH_DISPLAY_CTL_GPU_RECORD_GET, + RARCH_DISPLAY_CTL_GPU_RECORD_INIT, + RARCH_DISPLAY_CTL_GPU_RECORD_DEINIT }; typedef struct video_info diff --git a/record/record_driver.c b/record/record_driver.c index dd5bba682a..d88ae79b43 100644 --- a/record/record_driver.c +++ b/record/record_driver.c @@ -177,8 +177,9 @@ void recording_dump_frame(const void *data, unsigned width, ffemu_data.height = height; ffemu_data.data = data; - if (global->record.gpu_buffer) + if (video_driver_ctl(RARCH_DISPLAY_CTL_HAS_GPU_RECORD, NULL)) { + uint8_t *gpu_buf = NULL; struct video_viewport vp = {0}; video_driver_viewport_info(&vp); @@ -204,22 +205,24 @@ void recording_dump_frame(const void *data, unsigned width, return; } + if (!video_driver_ctl(RARCH_DISPLAY_CTL_GPU_RECORD_GET, &gpu_buf)) + return; + /* Big bottleneck. * Since we might need to do read-backs asynchronously, * it might take 3-4 times before this returns true. */ - if (!video_driver_ctl(RARCH_DISPLAY_CTL_READ_VIEWPORT, global->record.gpu_buffer)) + if (!video_driver_ctl(RARCH_DISPLAY_CTL_READ_VIEWPORT, gpu_buf)) return; ffemu_data.pitch = global->record.gpu_width * 3; ffemu_data.width = global->record.gpu_width; ffemu_data.height = global->record.gpu_height; - ffemu_data.data = global->record.gpu_buffer + - (ffemu_data.height - 1) * ffemu_data.pitch; + ffemu_data.data = gpu_buf + (ffemu_data.height - 1) * ffemu_data.pitch; ffemu_data.pitch = -ffemu_data.pitch; } - if (!global->record.gpu_buffer) + if (!video_driver_ctl(RARCH_DISPLAY_CTL_HAS_GPU_RECORD, NULL)) ffemu_data.is_dupe = !data; if (recording_driver && recording_driver->push_video) @@ -331,6 +334,7 @@ bool recording_init(void) if (video_driver_ctl(RARCH_DISPLAY_CTL_SUPPORTS_RECORDING, NULL)) { + unsigned gpu_size; struct video_viewport vp = {0}; video_driver_viewport_info(&vp); @@ -360,8 +364,8 @@ bool recording_init(void) RARCH_LOG("%s %u x %u\n", msg_hash_to_str(MSG_DETECTED_VIEWPORT_OF), vp.width, vp.height); - global->record.gpu_buffer = (uint8_t*)malloc(vp.width * vp.height * 3); - if (!global->record.gpu_buffer) + gpu_size = vp.width * vp.height * 3; + if (!video_driver_ctl(RARCH_DISPLAY_CTL_GPU_RECORD_INIT, &gpu_size)) return false; } else diff --git a/runloop.h b/runloop.h index 95235aef7c..b786e6945b 100644 --- a/runloop.h +++ b/runloop.h @@ -232,7 +232,6 @@ typedef struct global unsigned width; unsigned height; - uint8_t *gpu_buffer; size_t gpu_width; size_t gpu_height; char output_dir[PATH_MAX_LENGTH];