1
0
mirror of https://github.com/mpv-player/mpv synced 2025-02-03 05:31:34 +00:00

vo_gpu: move some extra code for screenshot to video.c

This also happens to fix some UB on the error path (target being
declared after the first "goto done;").
This commit is contained in:
wm4 2018-04-20 17:05:53 +02:00
parent 2e768ad0d8
commit 6435d9ae7f
2 changed files with 15 additions and 13 deletions

View File

@ -3169,15 +3169,23 @@ done:
void gl_video_screenshot(struct gl_video *p, struct vo_frame *frame,
struct voctrl_screenshot *args)
{
bool ok = false;
struct mp_image *res = NULL;
if (!p->ra->fns->tex_download)
return;
bool ok = false;
struct mp_image *res = NULL;
struct ra_tex *target = NULL;
struct mp_rect old_src = p->src_rect;
struct mp_rect old_dst = p->dst_rect;
struct mp_osd_res old_osd = p->osd_rect;
struct vo_frame *nframe = vo_frame_ref(frame);
// Disable interpolation and such.
nframe->redraw = true;
nframe->repeat = false;
nframe->still = true;
nframe->pts = 0;
nframe->duration = -1;
if (!args->scaled) {
int w, h;
@ -3216,7 +3224,7 @@ void gl_video_screenshot(struct gl_video *p, struct vo_frame *frame,
if (!params.format || !params.format->renderable)
goto done;
struct ra_tex *target = ra_tex_create(p->ra, &params);
target = ra_tex_create(p->ra, &params);
if (!target)
goto done;
@ -3225,7 +3233,7 @@ void gl_video_screenshot(struct gl_video *p, struct vo_frame *frame,
flags |= RENDER_FRAME_SUBS;
if (args->osd)
flags |= RENDER_FRAME_OSD;
gl_video_render_frame(p, frame, (struct ra_fbo){target}, flags);
gl_video_render_frame(p, nframe, (struct ra_fbo){target}, flags);
res = mp_image_alloc(mpfmt, params.w, params.h);
if (!res)
@ -3244,6 +3252,7 @@ void gl_video_screenshot(struct gl_video *p, struct vo_frame *frame,
ok = true;
done:
talloc_free(nframe);
ra_tex_free(p->ra, &target);
gl_video_resize(p, &old_src, &old_dst, &old_osd);
if (!ok)

View File

@ -178,15 +178,8 @@ static int control(struct vo *vo, uint32_t request, void *data)
return VO_TRUE;
case VOCTRL_SCREENSHOT: {
struct vo_frame *frame = vo_get_current_vo_frame(vo);
if (frame) {
// Disable interpolation and such.
frame->redraw = true;
frame->repeat = false;
frame->still = true;
frame->pts = 0;
frame->duration = -1;
if (frame)
gl_video_screenshot(p->renderer, frame, data);
}
talloc_free(frame);
return true;
}