(task_screenshot.c) Cleanups

This commit is contained in:
twinaphex 2019-04-13 04:56:11 +02:00
parent 95145ec0d4
commit 70373dba9a

View File

@ -82,20 +82,16 @@ struct screenshot_task_state
static bool screenshot_dump_direct(screenshot_task_state_t *state)
{
struct scaler_ctx *scaler = (struct scaler_ctx*)&state->scaler;
bool ret = false;
#ifdef HAVE_RBMP
enum rbmp_source_type bmp_type = RBMP_SOURCE_TYPE_DONT_CARE;
(void)bmp_type;
#endif
struct scaler_ctx *scaler = (struct scaler_ctx*)&state->scaler;
bool ret = false;
#if defined(HAVE_RPNG)
if (state->bgr24)
scaler->in_fmt = SCALER_FMT_BGR24;
scaler->in_fmt = SCALER_FMT_BGR24;
else if (state->pixel_format_type == RETRO_PIXEL_FORMAT_XRGB8888)
scaler->in_fmt = SCALER_FMT_ARGB8888;
scaler->in_fmt = SCALER_FMT_ARGB8888;
else
scaler->in_fmt = SCALER_FMT_RGB565;
scaler->in_fmt = SCALER_FMT_RGB565;
video_frame_convert_to_bgr24(
scaler,
@ -117,17 +113,20 @@ static bool screenshot_dump_direct(screenshot_task_state_t *state)
free(state->out_buffer);
#elif defined(HAVE_RBMP)
if (state->bgr24)
bmp_type = RBMP_SOURCE_TYPE_BGR24;
else if (state->pixel_format_type == RETRO_PIXEL_FORMAT_XRGB8888)
bmp_type = RBMP_SOURCE_TYPE_XRGB888;
{
enum rbmp_source_type bmp_type = RBMP_SOURCE_TYPE_DONT_CARE;
if (state->bgr24)
bmp_type = RBMP_SOURCE_TYPE_BGR24;
else if (state->pixel_format_type == RETRO_PIXEL_FORMAT_XRGB8888)
bmp_type = RBMP_SOURCE_TYPE_XRGB888;
ret = rbmp_save_image(state->filename,
state->frame,
state->width,
state->height,
state->pitch,
bmp_type);
ret = rbmp_save_image(state->filename,
state->frame,
state->width,
state->height,
state->pitch,
bmp_type);
}
#endif
#if defined(HAVE_MENU) && defined(HAVE_MENU_WIDGETS)
@ -174,9 +173,9 @@ static void task_screenshot_handler(retro_task_t *task)
struct playlist_entry entry = {0};
/* the push function reads our entry as const, so these casts are safe */
entry.path = state->filename;
entry.core_path = (char*)"builtin";
entry.core_name = (char*)"imageviewer";
entry.path = state->filename;
entry.core_path = (char*)"builtin";
entry.core_name = (char*)"imageviewer";
command_playlist_push_write(g_defaults.image_history, &entry);
}
@ -208,24 +207,19 @@ static bool screenshot_dump(
bool fullpath,
bool use_thread)
{
struct retro_system_info system_info;
char screenshot_path[PATH_MAX_LENGTH];
uint8_t *buf = NULL;
settings_t *settings = config_get_ptr();
retro_task_t *task;
screenshot_task_state_t *state;
const char *screenshot_dir = settings->paths.directory_screenshot;
struct retro_system_info system_info;
retro_task_t *task = task_init();
screenshot_task_state_t *state = (screenshot_task_state_t*)calloc(1, sizeof(*state));
state->shotname[0] = '\0';
screenshot_path[0] = '\0';
if (!core_get_system_info(&system_info))
return false;
task = task_init();
state = (screenshot_task_state_t*)calloc(1, sizeof(*state));
state->shotname[0] = '\0';
/* If fullpath is true, name_base already contains a static path + filename to save the screenshot to. */
/* If fullpath is true, name_base already contains a
* static path + filename to save the screenshot to. */
if (fullpath)
strlcpy(state->filename, name_base, sizeof(state->filename));
else
@ -263,6 +257,9 @@ static bool screenshot_dump(
if (path_is_empty(RARCH_PATH_CONTENT))
{
if (!core_get_system_info(&system_info))
return false;
if (string_is_empty(system_info.library_name))
screenshot_name = "RetroArch";
else
@ -306,33 +303,29 @@ static bool screenshot_dump(
task_free_title(task);
else
#endif
if (!savestate)
task->title = strdup(msg_hash_to_str(MSG_TAKING_SCREENSHOT));
if (!savestate)
task->title = strdup(msg_hash_to_str(MSG_TAKING_SCREENSHOT));
if (!task_queue_push(task))
{
/* There is already a blocking task going on */
if (task->title)
task_free_title(task);
if (task_queue_push(task))
return true;
free(task);
/* There is already a blocking task going on */
if (task->title)
task_free_title(task);
if (state->out_buffer)
free(state->out_buffer);
free(task);
free(state);
if (state->out_buffer)
free(state->out_buffer);
return false;
}
}
else
{
if (task)
free(task);
return screenshot_dump_direct(state);
free(state);
return false;
}
return true;
if (task)
free(task);
return screenshot_dump_direct(state);
}
#if !defined(VITA)
@ -341,7 +334,6 @@ static bool take_screenshot_viewport(const char *name_base, bool savestate,
{
struct video_viewport vp;
uint8_t *buffer = NULL;
bool retval = false;
vp.x = 0;
vp.y = 0;
@ -374,7 +366,7 @@ static bool take_screenshot_viewport(const char *name_base, bool savestate,
error:
if (buffer)
free(buffer);
return retval;
return false;
}
#endif
@ -392,7 +384,8 @@ static bool take_screenshot_raw(const char *name_base, void *userbuf,
*/
if (!screenshot_dump(name_base,
(const uint8_t*)data + (height - 1) * pitch,
width, height, (int)(-pitch), false, userbuf, savestate, is_idle, is_paused, fullpath, use_thread))
width, height, (int)(-pitch), false, userbuf, savestate,
is_idle, is_paused, fullpath, use_thread))
return false;
return true;
@ -403,7 +396,6 @@ static bool take_screenshot_choice(const char *name_base, bool savestate,
{
size_t old_pitch;
unsigned old_width, old_height;
bool ret = false;
void *frame_data = NULL;
const void* old_data = NULL;
settings_t *settings = config_get_ptr();
@ -446,13 +438,15 @@ static bool take_screenshot_choice(const char *name_base, bool savestate,
{
video_driver_set_cached_frame_ptr(frame_data);
if (take_screenshot_raw(name_base, frame_data, savestate, is_idle, is_paused, fullpath, use_thread))
ret = true;
return true;
}
return ret;
return false;
}
bool take_screenshot(const char *name_base, bool silence, bool has_valid_framebuffer, bool fullpath, bool use_thread)
bool take_screenshot(const char *name_base,
bool silence, bool has_valid_framebuffer,
bool fullpath, bool use_thread)
{
bool is_paused = false;
bool is_idle = false;