From 6286e4b74cb97e35af842e29064e35da8d8e06ef Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 20 Nov 2015 15:34:10 +0100 Subject: [PATCH] Add RARCH_DISPLAY_CTL_CACHED_FRAME_RENDER --- command_event.c | 2 +- gfx/drivers/gl.c | 2 +- gfx/drivers/sdl2_gfx.c | 2 +- gfx/video_driver.c | 71 ++++++++++++++++++++------------------ gfx/video_driver.h | 9 ++--- gfx/video_thread_wrapper.c | 2 +- menu/menu_display.c | 3 +- runloop.c | 4 +-- screenshot.c | 4 +-- 9 files changed, 49 insertions(+), 50 deletions(-) diff --git a/command_event.c b/command_event.c index cf8c33c1fa..2da8d6d219 100644 --- a/command_event.c +++ b/command_event.c @@ -1499,7 +1499,7 @@ bool event_command(enum event_command cmd) event_command(EVENT_CMD_AUDIO_STOP); if (settings->video.black_frame_insertion) - video_driver_cached_frame(); + video_driver_ctl(RARCH_DISPLAY_CTL_CACHED_FRAME_RENDER, NULL); } else { diff --git a/gfx/drivers/gl.c b/gfx/drivers/gl.c index a7a5bcd488..dc22666ee0 100644 --- a/gfx/drivers/gl.c +++ b/gfx/drivers/gl.c @@ -2950,7 +2950,7 @@ static bool gl_read_viewport(void *data, uint8_t *buffer) goto error; } - video_driver_cached_frame(); + video_driver_ctl(RARCH_DISPLAY_CTL_CACHED_FRAME_RENDER, NULL); dst = buffer; src = (const uint8_t*)gl->readback_buffer_screenshot; diff --git a/gfx/drivers/sdl2_gfx.c b/gfx/drivers/sdl2_gfx.c index 52bac26505..f05ba7b67a 100644 --- a/gfx/drivers/sdl2_gfx.c +++ b/gfx/drivers/sdl2_gfx.c @@ -627,7 +627,7 @@ static bool sdl2_gfx_read_viewport(void *data, uint8_t *buffer) rarch_perf_init(&sdl2_gfx_read_viewport, "sdl2_gfx_read_viewport"); retro_perf_start(&sdl2_gfx_read_viewport); - video_driver_cached_frame(); + video_driver_ctl(RARCH_DISPLAY_CTL_CACHED_FRAME_RENDER, NULL); surf = SDL_GetWindowSurface(vid->window); bgr24 = SDL_ConvertSurfaceFormat(surf, SDL_PIXELFORMAT_BGR24, 0); diff --git a/gfx/video_driver.c b/gfx/video_driver.c index bcbcc2ee1e..87d23940d9 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -790,39 +790,6 @@ void video_driver_get_video_output_prev(void) poke->get_video_output_prev(driver->video_data); } -/** - * video_driver_cached_frame: - * - * Renders the current video frame. - **/ -void video_driver_cached_frame(void) -{ - bool is_idle; - driver_t *driver = driver_get_ptr(); - void *recording = driver ? driver->recording_data : NULL; - - rarch_main_ctl(RARCH_MAIN_CTL_IS_IDLE, &is_idle); - - if (is_idle) - return; - - /* Cannot allow recording when pushing duped frames. */ - driver->recording_data = NULL; - - /* Not 100% safe, since the library might have - * freed the memory, but no known implementations do this. - * It would be really stupid at any rate ... - */ - if (driver->retro_ctx.frame_cb) - driver->retro_ctx.frame_cb( - (video_state.frame_cache.data == RETRO_HW_FRAME_BUFFER_VALID) - ? NULL : video_state.frame_cache.data, - video_state.frame_cache.width, - video_state.frame_cache.height, - video_state.frame_cache.pitch); - - driver->recording_data = recording; -} bool video_driver_cached_frame_has_valid_fb(void) { @@ -1179,11 +1146,49 @@ void video_driver_set_pixel_format(enum retro_pixel_format fmt) video_state.pix_fmt = fmt; } +/** + * video_driver_cached_frame: + * + * Renders the current video frame. + **/ +static bool video_driver_cached_frame(void) +{ + bool is_idle; + driver_t *driver = driver_get_ptr(); + void *recording = driver ? driver->recording_data : NULL; + + rarch_main_ctl(RARCH_MAIN_CTL_IS_IDLE, &is_idle); + + if (is_idle) + return true; /* Maybe return false here for indication of idleness? */ + + /* Cannot allow recording when pushing duped frames. */ + driver->recording_data = NULL; + + /* Not 100% safe, since the library might have + * freed the memory, but no known implementations do this. + * It would be really stupid at any rate ... + */ + if (driver->retro_ctx.frame_cb) + driver->retro_ctx.frame_cb( + (video_state.frame_cache.data == RETRO_HW_FRAME_BUFFER_VALID) + ? NULL : video_state.frame_cache.data, + video_state.frame_cache.width, + video_state.frame_cache.height, + video_state.frame_cache.pitch); + + driver->recording_data = recording; + + return true; +} + bool video_driver_ctl(enum rarch_display_ctl_state state, void *data) { switch (state) { + case RARCH_DISPLAY_CTL_CACHED_FRAME_RENDER: + return video_driver_cached_frame(); case RARCH_DISPLAY_CTL_IS_FOCUSED: { driver_t *driver = driver_get_ptr(); diff --git a/gfx/video_driver.h b/gfx/video_driver.h index 0719c2072f..94b266c282 100644 --- a/gfx/video_driver.h +++ b/gfx/video_driver.h @@ -225,6 +225,8 @@ enum rarch_display_ctl_state RARCH_DISPLAY_CTL_FRAME_FILTER_IS_32BIT, RARCH_DISPLAY_CTL_HAS_WINDOWED, RARCH_DISPLAY_CTL_IS_FOCUSED, + /* Renders the current video frame. */ + RARCH_DISPLAY_CTL_CACHED_FRAME_RENDER, RARCH_DISPLAY_CTL_GET_FRAME_COUNT }; @@ -368,13 +370,6 @@ enum retro_pixel_format video_driver_get_pixel_format(void); void video_driver_set_pixel_format(enum retro_pixel_format fmt); -/** - * video_driver_cached_frame: - * - * Renders the current video frame. - **/ -void video_driver_cached_frame(void); - void video_driver_cached_frame_set(const void *data, unsigned width, unsigned height, size_t pitch); diff --git a/gfx/video_thread_wrapper.c b/gfx/video_thread_wrapper.c index 5a73af48f3..3671c2629d 100644 --- a/gfx/video_thread_wrapper.c +++ b/gfx/video_thread_wrapper.c @@ -169,7 +169,7 @@ static bool thread_handle_packet(thread_video_t *thr, const thread_packet_t *inc /* We can read safely * * read_viewport() in GL driver calls - * video_driver_cached_frame() to be able to read from + * 'cached frame render' to be able to read from * back buffer. * * This means frame() callback in threaded wrapper will diff --git a/menu/menu_display.c b/menu/menu_display.c index d440d01a6b..80500c4fdd 100644 --- a/menu/menu_display.c +++ b/menu/menu_display.c @@ -324,8 +324,7 @@ bool menu_display_ctl(enum menu_display_ctl_state state, void *data) return true; } - video_driver_cached_frame(); - return true; + return video_driver_ctl(RARCH_DISPLAY_CTL_CACHED_FRAME_RENDER, NULL); case MENU_DISPLAY_CTL_SET_WIDTH: { unsigned *ptr = (unsigned*)data; diff --git a/runloop.c b/runloop.c index 1cbc2eb5de..5744e93a34 100644 --- a/runloop.c +++ b/runloop.c @@ -449,7 +449,7 @@ bool rarch_main_ctl(enum rarch_main_ctl_state state, void *data) if (cmd->fullscreen_toggle) { event_command(EVENT_CMD_FULLSCREEN_TOGGLE); - video_driver_cached_frame(); + video_driver_ctl(RARCH_DISPLAY_CTL_CACHED_FRAME_RENDER, NULL); } if (!check_is_oneshot) @@ -469,7 +469,7 @@ bool rarch_main_ctl(enum rarch_main_ctl_state state, void *data) return false; if (settings->video.black_frame_insertion) - video_driver_cached_frame(); + video_driver_ctl(RARCH_DISPLAY_CTL_CACHED_FRAME_RENDER, NULL); if (state_manager_frame_is_reversed()) rarch_main_msg_queue_push_new(MSG_SLOW_MOTION_REWIND, 0, 30, true); diff --git a/screenshot.c b/screenshot.c index 42b41e127e..347dbdfd29 100644 --- a/screenshot.c +++ b/screenshot.c @@ -229,7 +229,7 @@ bool take_screenshot(void) video_driver_set_texture_enable(false, false); if (driver->video) - video_driver_cached_frame(); + video_driver_ctl(RARCH_DISPLAY_CTL_CACHED_FRAME_RENDER, NULL); } if (viewport_read) @@ -284,7 +284,7 @@ bool take_screenshot(void) rarch_main_msg_queue_push(msg, 1, is_paused ? 1 : 180, true); if (is_paused) - video_driver_cached_frame(); + video_driver_ctl(RARCH_DISPLAY_CTL_CACHED_FRAME_RENDER, NULL); return ret; }