mirror of
https://github.com/libretro/RetroArch
synced 2025-04-01 13:20:43 +00:00
(task_screenshot.c) Simplify code
This commit is contained in:
parent
2d33c49b26
commit
69605b7c9c
@ -122,14 +122,10 @@ static void task_screenshot_handler(retro_task_t *task)
|
|||||||
if (!task)
|
if (!task)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
state = (screenshot_task_state_t*)task->state;
|
if (!(state = (screenshot_task_state_t*)task->state))
|
||||||
|
|
||||||
if (!state)
|
|
||||||
goto task_finished;
|
goto task_finished;
|
||||||
|
|
||||||
if (task_get_cancelled(task))
|
if (task_get_cancelled(task))
|
||||||
goto task_finished;
|
goto task_finished;
|
||||||
|
|
||||||
if (task_get_progress(task) == 100)
|
if (task_get_progress(task) == 100)
|
||||||
goto task_finished;
|
goto task_finished;
|
||||||
|
|
||||||
@ -412,17 +408,11 @@ static bool take_screenshot_viewport(
|
|||||||
|
|
||||||
if (!vp.width || !vp.height)
|
if (!vp.width || !vp.height)
|
||||||
return false;
|
return false;
|
||||||
|
if (!(buffer = (uint8_t*)malloc(vp.width * vp.height * 3)))
|
||||||
buffer = (uint8_t*)malloc(vp.width * vp.height * 3);
|
|
||||||
|
|
||||||
if (!buffer)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!video_driver_read_viewport(buffer, is_idle))
|
if (!video_driver_read_viewport(buffer, is_idle))
|
||||||
{
|
goto error;
|
||||||
free(buffer);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Data read from viewport is in bottom-up order, suitable for BMP. */
|
/* Data read from viewport is in bottom-up order, suitable for BMP. */
|
||||||
if (!screenshot_dump(screenshot_dir,
|
if (!screenshot_dump(screenshot_dir,
|
||||||
@ -431,12 +421,13 @@ static bool take_screenshot_viewport(
|
|||||||
vp.width * 3, true, buffer,
|
vp.width * 3, true, buffer,
|
||||||
savestate, is_idle, is_paused, fullpath, use_thread,
|
savestate, is_idle, is_paused, fullpath, use_thread,
|
||||||
pixel_format_type))
|
pixel_format_type))
|
||||||
{
|
goto error;
|
||||||
free(buffer);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
error:
|
||||||
|
free(buffer);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool take_screenshot_raw(const char *screenshot_dir,
|
static bool take_screenshot_raw(const char *screenshot_dir,
|
||||||
@ -447,13 +438,11 @@ static bool take_screenshot_raw(const char *screenshot_dir,
|
|||||||
size_t pitch;
|
size_t pitch;
|
||||||
unsigned width, height;
|
unsigned width, height;
|
||||||
const void *data = NULL;
|
const void *data = NULL;
|
||||||
|
|
||||||
video_driver_cached_frame_get(&data, &width, &height, &pitch);
|
video_driver_cached_frame_get(&data, &width, &height, &pitch);
|
||||||
|
|
||||||
/* Negative pitch is needed as screenshot takes bottom-up,
|
/* Negative pitch is needed as screenshot takes bottom-up,
|
||||||
* but we use top-down.
|
* but we use top-down.
|
||||||
*/
|
*/
|
||||||
if (!screenshot_dump(screenshot_dir,
|
return screenshot_dump(screenshot_dir,
|
||||||
name_base,
|
name_base,
|
||||||
(const uint8_t*)data + (height - 1) * pitch,
|
(const uint8_t*)data + (height - 1) * pitch,
|
||||||
width,
|
width,
|
||||||
@ -466,10 +455,7 @@ static bool take_screenshot_raw(const char *screenshot_dir,
|
|||||||
is_paused,
|
is_paused,
|
||||||
fullpath,
|
fullpath,
|
||||||
use_thread,
|
use_thread,
|
||||||
pixel_format_type))
|
pixel_format_type);
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool take_screenshot_choice(
|
static bool take_screenshot_choice(
|
||||||
@ -486,11 +472,6 @@ static bool take_screenshot_choice(
|
|||||||
unsigned pixel_format_type
|
unsigned pixel_format_type
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
size_t old_pitch;
|
|
||||||
unsigned old_width, old_height;
|
|
||||||
void *frame_data = NULL;
|
|
||||||
const void* old_data = NULL;
|
|
||||||
|
|
||||||
if (supports_viewport_read)
|
if (supports_viewport_read)
|
||||||
{
|
{
|
||||||
/* Avoid taking screenshot of GUI overlays. */
|
/* Avoid taking screenshot of GUI overlays. */
|
||||||
@ -507,25 +488,28 @@ static bool take_screenshot_choice(
|
|||||||
name_base, NULL, savestate, is_idle, is_paused, fullpath, use_thread,
|
name_base, NULL, savestate, is_idle, is_paused, fullpath, use_thread,
|
||||||
pixel_format_type);
|
pixel_format_type);
|
||||||
|
|
||||||
if (!supports_read_frame_raw)
|
if (supports_read_frame_raw)
|
||||||
return false;
|
|
||||||
|
|
||||||
video_driver_cached_frame_get(&old_data, &old_width, &old_height,
|
|
||||||
&old_pitch);
|
|
||||||
|
|
||||||
frame_data = video_driver_read_frame_raw(
|
|
||||||
&old_width, &old_height, &old_pitch);
|
|
||||||
|
|
||||||
video_driver_cached_frame_set(old_data, old_width, old_height,
|
|
||||||
old_pitch);
|
|
||||||
|
|
||||||
if (frame_data)
|
|
||||||
{
|
{
|
||||||
video_driver_set_cached_frame_ptr(frame_data);
|
size_t old_pitch;
|
||||||
if (take_screenshot_raw(screenshot_dir,
|
unsigned old_width, old_height;
|
||||||
|
void *frame_data = NULL;
|
||||||
|
const void* old_data = NULL;
|
||||||
|
video_driver_cached_frame_get(&old_data, &old_width, &old_height,
|
||||||
|
&old_pitch);
|
||||||
|
|
||||||
|
frame_data = video_driver_read_frame_raw(
|
||||||
|
&old_width, &old_height, &old_pitch);
|
||||||
|
|
||||||
|
video_driver_cached_frame_set(old_data, old_width, old_height,
|
||||||
|
old_pitch);
|
||||||
|
|
||||||
|
if (frame_data)
|
||||||
|
{
|
||||||
|
video_driver_set_cached_frame_ptr(frame_data);
|
||||||
|
return take_screenshot_raw(screenshot_dir,
|
||||||
name_base, frame_data, savestate, is_idle, is_paused, fullpath, use_thread,
|
name_base, frame_data, savestate, is_idle, is_paused, fullpath, use_thread,
|
||||||
pixel_format_type))
|
pixel_format_type);
|
||||||
return true;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user