mirror of
https://github.com/libretro/RetroArch
synced 2025-04-01 04:20:27 +00:00
(task_save) Use flags instead of booleans
(task_screenshot) Start reducing amount of parameters
This commit is contained in:
parent
11047c6f4d
commit
07378abbdf
@ -135,6 +135,12 @@ struct autosave_st
|
|||||||
unsigned num;
|
unsigned num;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum autosave_flags
|
||||||
|
{
|
||||||
|
AUTOSAVE_FLAG_QUIT = (1 << 0),
|
||||||
|
AUTOSAVE_FLAG_COMPRESS_FILES = (1 << 1)
|
||||||
|
};
|
||||||
|
|
||||||
struct autosave
|
struct autosave
|
||||||
{
|
{
|
||||||
void *buffer;
|
void *buffer;
|
||||||
@ -146,8 +152,7 @@ struct autosave
|
|||||||
sthread_t *thread;
|
sthread_t *thread;
|
||||||
size_t bufsize;
|
size_t bufsize;
|
||||||
unsigned interval;
|
unsigned interval;
|
||||||
bool quit;
|
uint8_t flags;
|
||||||
bool compress_files;
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -208,7 +213,7 @@ static void autosave_thread(void *data)
|
|||||||
intfstream_t *file = NULL;
|
intfstream_t *file = NULL;
|
||||||
|
|
||||||
/* Should probably deal with this more elegantly. */
|
/* Should probably deal with this more elegantly. */
|
||||||
if (save->compress_files)
|
if (save->flags & AUTOSAVE_FLAG_COMPRESS_FILES)
|
||||||
file = intfstream_open_rzip_file(save->path,
|
file = intfstream_open_rzip_file(save->path,
|
||||||
RETRO_VFS_FILE_ACCESS_WRITE);
|
RETRO_VFS_FILE_ACCESS_WRITE);
|
||||||
else
|
else
|
||||||
@ -226,7 +231,7 @@ static void autosave_thread(void *data)
|
|||||||
|
|
||||||
slock_lock(save->cond_lock);
|
slock_lock(save->cond_lock);
|
||||||
|
|
||||||
if (save->quit)
|
if (save->flags & AUTOSAVE_FLAG_QUIT)
|
||||||
{
|
{
|
||||||
slock_unlock(save->cond_lock);
|
slock_unlock(save->cond_lock);
|
||||||
break;
|
break;
|
||||||
@ -266,10 +271,11 @@ static autosave_t *autosave_new(const char *path,
|
|||||||
if (!handle)
|
if (!handle)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
handle->quit = false;
|
handle->flags = 0;
|
||||||
handle->bufsize = size;
|
handle->bufsize = size;
|
||||||
handle->interval = interval;
|
handle->interval = interval;
|
||||||
handle->compress_files = compress;
|
if (compress)
|
||||||
|
handle->flags |= AUTOSAVE_FLAG_COMPRESS_FILES;
|
||||||
handle->retro_buffer = data;
|
handle->retro_buffer = data;
|
||||||
handle->path = path;
|
handle->path = path;
|
||||||
|
|
||||||
@ -300,7 +306,7 @@ static autosave_t *autosave_new(const char *path,
|
|||||||
static void autosave_free(autosave_t *handle)
|
static void autosave_free(autosave_t *handle)
|
||||||
{
|
{
|
||||||
slock_lock(handle->cond_lock);
|
slock_lock(handle->cond_lock);
|
||||||
handle->quit = true;
|
handle->flags |= AUTOSAVE_FLAG_QUIT;
|
||||||
slock_unlock(handle->cond_lock);
|
slock_unlock(handle->cond_lock);
|
||||||
scond_signal(handle->cond);
|
scond_signal(handle->cond);
|
||||||
sthread_join(handle->thread);
|
sthread_join(handle->thread);
|
||||||
|
@ -227,8 +227,7 @@ static bool screenshot_dump(
|
|||||||
bool bgr24,
|
bool bgr24,
|
||||||
void *userbuf,
|
void *userbuf,
|
||||||
bool savestate,
|
bool savestate,
|
||||||
bool is_idle,
|
uint32_t runloop_flags,
|
||||||
bool is_paused,
|
|
||||||
bool fullpath,
|
bool fullpath,
|
||||||
bool use_thread,
|
bool use_thread,
|
||||||
unsigned pixel_format_type)
|
unsigned pixel_format_type)
|
||||||
@ -245,9 +244,9 @@ static bool screenshot_dump(
|
|||||||
if (fullpath)
|
if (fullpath)
|
||||||
strlcpy(state->filename, name_base, sizeof(state->filename));
|
strlcpy(state->filename, name_base, sizeof(state->filename));
|
||||||
|
|
||||||
if (is_idle)
|
if (runloop_flags & RUNLOOP_FLAG_IDLE)
|
||||||
state->flags |= SS_TASK_FLAG_IS_IDLE;
|
state->flags |= SS_TASK_FLAG_IS_IDLE;
|
||||||
if (is_paused)
|
if (runloop_flags & RUNLOOP_FLAG_PAUSED)
|
||||||
state->flags |= SS_TASK_FLAG_IS_PAUSED;
|
state->flags |= SS_TASK_FLAG_IS_PAUSED;
|
||||||
if (bgr24)
|
if (bgr24)
|
||||||
state->flags |= SS_TASK_FLAG_BGR24;
|
state->flags |= SS_TASK_FLAG_BGR24;
|
||||||
@ -412,8 +411,7 @@ static bool take_screenshot_viewport(
|
|||||||
const char *screenshot_dir,
|
const char *screenshot_dir,
|
||||||
const char *name_base,
|
const char *name_base,
|
||||||
bool savestate,
|
bool savestate,
|
||||||
bool is_idle,
|
uint32_t runloop_flags,
|
||||||
bool is_paused,
|
|
||||||
bool fullpath,
|
bool fullpath,
|
||||||
bool use_thread,
|
bool use_thread,
|
||||||
unsigned pixel_format_type)
|
unsigned pixel_format_type)
|
||||||
@ -435,7 +433,7 @@ static bool take_screenshot_viewport(
|
|||||||
if (!(buffer = (uint8_t*)malloc(vp.width * vp.height * 3)))
|
if (!(buffer = (uint8_t*)malloc(vp.width * vp.height * 3)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!video_driver_read_viewport(buffer, is_idle))
|
if (!video_driver_read_viewport(buffer, runloop_flags & RUNLOOP_FLAG_IDLE))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
/* Data read from viewport is in bottom-up order, suitable for BMP. */
|
/* Data read from viewport is in bottom-up order, suitable for BMP. */
|
||||||
@ -443,7 +441,7 @@ static bool take_screenshot_viewport(
|
|||||||
name_base,
|
name_base,
|
||||||
buffer, vp.width, vp.height,
|
buffer, vp.width, vp.height,
|
||||||
vp.width * 3, true, buffer,
|
vp.width * 3, true, buffer,
|
||||||
savestate, is_idle, is_paused, fullpath, use_thread,
|
savestate, runloop_flags, fullpath, use_thread,
|
||||||
pixel_format_type))
|
pixel_format_type))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
@ -456,7 +454,7 @@ error:
|
|||||||
|
|
||||||
static bool take_screenshot_raw(const char *screenshot_dir,
|
static bool take_screenshot_raw(const char *screenshot_dir,
|
||||||
const char *name_base, void *userbuf,
|
const char *name_base, void *userbuf,
|
||||||
bool savestate, bool is_idle, bool is_paused, bool fullpath, bool use_thread,
|
bool savestate, uint32_t runloop_flags, bool fullpath, bool use_thread,
|
||||||
unsigned pixel_format_type)
|
unsigned pixel_format_type)
|
||||||
{
|
{
|
||||||
size_t pitch;
|
size_t pitch;
|
||||||
@ -475,8 +473,7 @@ static bool take_screenshot_raw(const char *screenshot_dir,
|
|||||||
false,
|
false,
|
||||||
userbuf,
|
userbuf,
|
||||||
savestate,
|
savestate,
|
||||||
is_idle,
|
runloop_flags,
|
||||||
is_paused,
|
|
||||||
fullpath,
|
fullpath,
|
||||||
use_thread,
|
use_thread,
|
||||||
pixel_format_type);
|
pixel_format_type);
|
||||||
@ -486,8 +483,7 @@ static bool take_screenshot_choice(
|
|||||||
const char *screenshot_dir,
|
const char *screenshot_dir,
|
||||||
const char *name_base,
|
const char *name_base,
|
||||||
bool savestate,
|
bool savestate,
|
||||||
bool is_paused,
|
uint32_t runloop_flags,
|
||||||
bool is_idle,
|
|
||||||
bool has_valid_framebuffer,
|
bool has_valid_framebuffer,
|
||||||
bool fullpath,
|
bool fullpath,
|
||||||
bool use_thread,
|
bool use_thread,
|
||||||
@ -500,16 +496,16 @@ static bool take_screenshot_choice(
|
|||||||
{
|
{
|
||||||
/* Avoid taking screenshot of GUI overlays. */
|
/* Avoid taking screenshot of GUI overlays. */
|
||||||
video_driver_set_texture_enable(false, false);
|
video_driver_set_texture_enable(false, false);
|
||||||
if (!is_idle)
|
if (!(runloop_flags & RUNLOOP_FLAG_IDLE))
|
||||||
video_driver_cached_frame();
|
video_driver_cached_frame();
|
||||||
return take_screenshot_viewport(screenshot_dir,
|
return take_screenshot_viewport(screenshot_dir,
|
||||||
name_base, savestate, is_idle, is_paused, fullpath, use_thread,
|
name_base, savestate, runloop_flags, fullpath, use_thread,
|
||||||
pixel_format_type);
|
pixel_format_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!has_valid_framebuffer)
|
if (!has_valid_framebuffer)
|
||||||
return take_screenshot_raw(screenshot_dir,
|
return take_screenshot_raw(screenshot_dir,
|
||||||
name_base, NULL, savestate, is_idle, is_paused, fullpath, use_thread,
|
name_base, NULL, savestate, runloop_flags, fullpath, use_thread,
|
||||||
pixel_format_type);
|
pixel_format_type);
|
||||||
|
|
||||||
if (supports_read_frame_raw)
|
if (supports_read_frame_raw)
|
||||||
@ -531,7 +527,7 @@ static bool take_screenshot_choice(
|
|||||||
{
|
{
|
||||||
video_driver_set_cached_frame_ptr(frame_data);
|
video_driver_set_cached_frame_ptr(frame_data);
|
||||||
return take_screenshot_raw(screenshot_dir,
|
return take_screenshot_raw(screenshot_dir,
|
||||||
name_base, frame_data, savestate, is_idle, is_paused, fullpath, use_thread,
|
name_base, frame_data, savestate, runloop_flags, fullpath, use_thread,
|
||||||
pixel_format_type);
|
pixel_format_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -545,12 +541,10 @@ bool take_screenshot(
|
|||||||
bool savestate, bool has_valid_framebuffer,
|
bool savestate, bool has_valid_framebuffer,
|
||||||
bool fullpath, bool use_thread)
|
bool fullpath, bool use_thread)
|
||||||
{
|
{
|
||||||
|
bool ret = false;
|
||||||
uint32_t runloop_flags = runloop_get_flags();
|
uint32_t runloop_flags = runloop_get_flags();
|
||||||
settings_t *settings = config_get_ptr();
|
settings_t *settings = config_get_ptr();
|
||||||
bool video_gpu_screenshot = settings->bools.video_gpu_screenshot;
|
bool video_gpu_screenshot = settings->bools.video_gpu_screenshot;
|
||||||
bool is_paused = false;
|
|
||||||
bool is_idle = false;
|
|
||||||
bool ret = false;
|
|
||||||
bool supports_viewport_read = video_driver_supports_viewport_read();
|
bool supports_viewport_read = video_driver_supports_viewport_read();
|
||||||
bool prefer_viewport_read = supports_viewport_read &&
|
bool prefer_viewport_read = supports_viewport_read &&
|
||||||
video_driver_prefer_viewport_read();
|
video_driver_prefer_viewport_read();
|
||||||
@ -559,9 +553,6 @@ bool take_screenshot(
|
|||||||
if (supports_viewport_read && video_gpu_screenshot && !savestate)
|
if (supports_viewport_read && video_gpu_screenshot && !savestate)
|
||||||
prefer_viewport_read = true;
|
prefer_viewport_read = true;
|
||||||
|
|
||||||
is_paused = runloop_flags & RUNLOOP_FLAG_PAUSED;
|
|
||||||
is_idle = runloop_flags & RUNLOOP_FLAG_IDLE;
|
|
||||||
|
|
||||||
/* No way to infer screenshot directory. */
|
/* No way to infer screenshot directory. */
|
||||||
if ( string_is_empty(screenshot_dir)
|
if ( string_is_empty(screenshot_dir)
|
||||||
&& string_is_empty(name_base))
|
&& string_is_empty(name_base))
|
||||||
@ -569,14 +560,15 @@ bool take_screenshot(
|
|||||||
|
|
||||||
ret = take_screenshot_choice(
|
ret = take_screenshot_choice(
|
||||||
screenshot_dir,
|
screenshot_dir,
|
||||||
name_base, savestate, is_paused, is_idle,
|
name_base, savestate, runloop_flags,
|
||||||
has_valid_framebuffer, fullpath, use_thread,
|
has_valid_framebuffer, fullpath, use_thread,
|
||||||
prefer_viewport_read,
|
prefer_viewport_read,
|
||||||
video_driver_supports_read_frame_raw(),
|
video_driver_supports_read_frame_raw(),
|
||||||
video_driver_get_pixel_format()
|
video_driver_get_pixel_format()
|
||||||
);
|
);
|
||||||
|
|
||||||
if (is_paused && !is_idle)
|
if ( (runloop_flags & RUNLOOP_FLAG_PAUSED)
|
||||||
|
&& (!(runloop_flags & RUNLOOP_FLAG_IDLE)))
|
||||||
video_driver_cached_frame();
|
video_driver_cached_frame();
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user