Skip to content

Commit

Permalink
vo: fully replace draw_image with draw_frame
Browse files Browse the repository at this point in the history
0739cfc added the draw_frame API
deprecated draw_image internally. VOs that still used draw_image were
around, but really there's no reason to not just "upgrade" them anyway.
draw_frame is what the "real" VOs that people care about (gpu/gpu-next)
use. So we can just simplfy the code a bit now. VOCTRL_REDRAW_FRAME is
also no longer needed so that can be completely deleted as well. Note
that several of these VOs are legacy crap anyway (e.g. vaapi and vdpau)
and maybe should just be deleted but whatever. vo_direct3d was also
completely untested (not that anyone should ever use it).
  • Loading branch information
Dudemanguy committed Sep 26, 2023
1 parent b4260be commit b39c3d1
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 128 deletions.
15 changes: 2 additions & 13 deletions video/out/vo.c
Original file line number Diff line number Diff line change
Expand Up @@ -968,11 +968,7 @@ static bool render_frame(struct vo *vo)

stats_time_start(in->stats, "video-draw");

if (vo->driver->draw_frame) {
vo->driver->draw_frame(vo, frame);
} else {
vo->driver->draw_image(vo, mp_image_new_ref(frame->current));
}
vo->driver->draw_frame(vo, frame);

stats_time_end(in->stats, "video-draw");

Expand Down Expand Up @@ -1065,14 +1061,7 @@ static void do_redraw(struct vo *vo)
frame->duration = -1;
pthread_mutex_unlock(&in->lock);

if (vo->driver->draw_frame) {
vo->driver->draw_frame(vo, frame);
} else if ((full_redraw || vo->driver->control(vo, VOCTRL_REDRAW_FRAME, NULL) < 1)
&& frame->current)
{
vo->driver->draw_image(vo, mp_image_new_ref(frame->current));
}

vo->driver->draw_frame(vo, frame);
vo->driver->flip_page(vo);

if (frame != &dummy)
Expand Down
16 changes: 0 additions & 16 deletions video/out/vo.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ enum mp_voctrl {
/* private to vo_gpu */
VOCTRL_LOAD_HWDEC_API,

// Redraw the image previously passed to draw_image() (basically, repeat
// the previous draw_image call). If this is handled, the OSD should also
// be updated and redrawn. Optional; emulated if not available.
VOCTRL_REDRAW_FRAME,

// Only used internally in vo_libmpv
VOCTRL_PREINIT,
VOCTRL_UNINIT,
Expand Down Expand Up @@ -383,17 +378,6 @@ struct vo_driver {
struct mp_image *(*get_image_ts)(struct vo *vo, int imgfmt, int w, int h,
int stride_align, int flags);

/*
* Render the given frame to the VO's backbuffer. This operation will be
* followed by a draw_osd and a flip_page[_timed] call.
* mpi belongs to the VO; the VO must free it eventually.
*
* This also should draw the OSD.
*
* Deprecated for draw_frame. A VO should have only either callback set.
*/
void (*draw_image)(struct vo *vo, struct mp_image *mpi);

/* Render the given frame. Note that this is also called when repeating
* or redrawing frames.
*
Expand Down
8 changes: 5 additions & 3 deletions video/out/vo_caca.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,15 @@ static int reconfig(struct vo *vo, struct mp_image_params *params)
return resize(vo);
}

static void draw_image(struct vo *vo, mp_image_t *mpi)
static void draw_frame(struct vo *vo, struct vo_frame *frame)
{
struct priv *priv = vo->priv;
struct mp_image *mpi = frame->current;
if (!mpi)
return;
memcpy_pic(priv->dither_buffer, mpi->planes[0], priv->image_width * depth, priv->image_height,
priv->image_width * depth, mpi->stride[0]);
caca_dither_bitmap(priv->canvas, 0, 0, priv->screen_w, priv->screen_h, priv->dither, priv->dither_buffer);
talloc_free(mpi);
}

static void flip_page(struct vo *vo)
Expand Down Expand Up @@ -305,7 +307,7 @@ const struct vo_driver video_out_caca = {
.query_format = query_format,
.reconfig = reconfig,
.control = control,
.draw_image = draw_image,
.draw_frame = draw_frame,
.flip_page = flip_page,
.uninit = uninit,
.priv_size = sizeof(struct priv),
Expand Down
21 changes: 9 additions & 12 deletions video/out/vo_direct3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -850,9 +850,6 @@ static int control(struct vo *vo, uint32_t request, void *data)
d3d_priv *priv = vo->priv;

switch (request) {
case VOCTRL_REDRAW_FRAME:
d3d_draw_frame(priv);
return VO_TRUE;
case VOCTRL_SET_PANSCAN:
calc_fs_rect(priv);
priv->vo->want_redraw = true;
Expand Down Expand Up @@ -993,27 +990,27 @@ static bool get_video_buffer(d3d_priv *priv, struct mp_image *out)
return true;
}

static void draw_image(struct vo *vo, mp_image_t *mpi)
static void draw_frame(struct vo *vo, struct vo_frame *frame)
{
d3d_priv *priv = vo->priv;
if (!priv->d3d_device)
goto done;
return;

struct mp_image buffer;
if (!get_video_buffer(priv, &buffer))
goto done;
return;

mp_image_copy(&buffer, mpi);
if (!frame->current)
return;

mp_image_copy(&buffer, frame->current);

d3d_unlock_video_objects(priv);

priv->have_image = true;
priv->osd_pts = mpi->pts;
priv->osd_pts = frame->current->pts;

d3d_draw_frame(priv);

done:
talloc_free(mpi);
}

static mp_image_t *get_window_screenshot(d3d_priv *priv)
Expand Down Expand Up @@ -1242,7 +1239,7 @@ const struct vo_driver video_out_direct3d = {
.query_format = query_format,
.reconfig = reconfig,
.control = control,
.draw_image = draw_image,
.draw_frame = draw_frame,
.flip_page = flip_page,
.uninit = uninit,
.priv_size = sizeof(d3d_priv),
Expand Down
17 changes: 6 additions & 11 deletions video/out/vo_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,19 @@ static bool checked_mkdir(struct vo *vo, const char *buf)

static int reconfig(struct vo *vo, struct mp_image_params *params)
{
struct priv *p = vo->priv;
mp_image_unrefp(&p->current);

return 0;
}

static void draw_image(struct vo *vo, mp_image_t *mpi)
static void draw_frame(struct vo *vo, struct vo_frame *frame)
{
struct priv *p = vo->priv;
if (!frame->current)
return;

p->current = mpi;
p->current = frame->current;

struct mp_osd_res dim = osd_res_from_image_params(vo->params);
osd_draw_on_image(vo->osd, dim, mpi->pts, OSD_DRAW_SUB_ONLY, p->current);
osd_draw_on_image(vo->osd, dim, frame->current->pts, OSD_DRAW_SUB_ONLY, p->current);
}

static void flip_page(struct vo *vo)
Expand All @@ -122,7 +121,6 @@ static void flip_page(struct vo *vo)
write_image(p->current, p->opts->opts, filename, vo->global, vo->log);

talloc_free(t);
mp_image_unrefp(&p->current);
}

static int query_format(struct vo *vo, int fmt)
Expand All @@ -134,9 +132,6 @@ static int query_format(struct vo *vo, int fmt)

static void uninit(struct vo *vo)
{
struct priv *p = vo->priv;

mp_image_unrefp(&p->current);
}

static int preinit(struct vo *vo)
Expand All @@ -163,7 +158,7 @@ const struct vo_driver video_out_image =
.query_format = query_format,
.reconfig = reconfig,
.control = control,
.draw_image = draw_image,
.draw_frame = draw_frame,
.flip_page = flip_page,
.uninit = uninit,
.global_opts = &vo_image_conf,
Expand Down
5 changes: 2 additions & 3 deletions video/out/vo_null.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ struct priv {
double cfg_fps;
};

static void draw_image(struct vo *vo, mp_image_t *mpi)
static void draw_frame(struct vo *vo, struct vo_frame *frame)
{
talloc_free(mpi);
}

static void flip_page(struct vo *vo)
Expand Down Expand Up @@ -93,7 +92,7 @@ const struct vo_driver video_out_null = {
.query_format = query_format,
.reconfig = reconfig,
.control = control,
.draw_image = draw_image,
.draw_frame = draw_frame,
.flip_page = flip_page,
.uninit = uninit,
.priv_size = sizeof(struct priv),
Expand Down
19 changes: 6 additions & 13 deletions video/out/vo_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ static int query_format(struct vo *vo, int format)
return 0;
}

static void draw_image(struct vo *vo, mp_image_t *mpi)
static void draw_frame(struct vo *vo, struct vo_frame *frame)
{
struct priv *vc = vo->priv;

Expand All @@ -879,20 +879,16 @@ static void draw_image(struct vo *vo, mp_image_t *mpi)

SDL_SetTextureBlendMode(vc->tex, SDL_BLENDMODE_NONE);

if (mpi) {
vc->osd_pts = mpi->pts;
if (frame->current) {
vc->osd_pts = frame->current->pts;

mp_image_t texmpi;
if (!lock_texture(vo, &texmpi)) {
talloc_free(mpi);
if (!lock_texture(vo, &texmpi))
return;
}

mp_image_copy(&texmpi, mpi);
mp_image_copy(&texmpi, frame->current);

SDL_UnlockTexture(vc->tex);

talloc_free(mpi);
}

SDL_Rect src, dst;
Expand Down Expand Up @@ -940,9 +936,6 @@ static int control(struct vo *vo, uint32_t request, void *data)
}
return 1;
}
case VOCTRL_REDRAW_FRAME:
draw_image(vo, NULL);
return 1;
case VOCTRL_SET_PANSCAN:
force_resize(vo);
return VO_TRUE;
Expand Down Expand Up @@ -987,7 +980,7 @@ const struct vo_driver video_out_sdl = {
.query_format = query_format,
.reconfig = reconfig,
.control = control,
.draw_image = draw_image,
.draw_frame = draw_frame,
.uninit = uninit,
.flip_page = flip_page,
.wait_events = wait_events,
Expand Down
11 changes: 6 additions & 5 deletions video/out/vo_tct.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,14 @@ static int reconfig(struct vo *vo, struct mp_image_params *params)
return 0;
}

static void draw_image(struct vo *vo, mp_image_t *mpi)
static void draw_frame(struct vo *vo, struct vo_frame *frame)
{
struct priv *p = vo->priv;
struct mp_image src = *mpi;
struct mp_image *src = frame->current;
if (!src)
return;
// XXX: pan, crop etc.
mp_sws_scale(p->sws, p->frame, &src);
talloc_free(mpi);
mp_sws_scale(p->sws, p->frame, src);
}

static void flip_page(struct vo *vo)
Expand Down Expand Up @@ -326,7 +327,7 @@ const struct vo_driver video_out_tct = {
.query_format = query_format,
.reconfig = reconfig,
.control = control,
.draw_image = draw_image,
.draw_frame = draw_frame,
.flip_page = flip_page,
.uninit = uninit,
.priv_size = sizeof(struct priv),
Expand Down
18 changes: 8 additions & 10 deletions video/out/vo_vaapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,24 +563,26 @@ static void get_vsync(struct vo *vo, struct vo_vsync_info *info)
present_sync_get_info(x11->present, info);
}

static void draw_image(struct vo *vo, struct mp_image *mpi)
static void draw_frame(struct vo *vo, struct vo_frame *frame)
{
struct priv *p = vo->priv;
struct mp_image *mpi = frame->current;

if (mpi->imgfmt != IMGFMT_VAAPI) {
if (mpi && mpi->imgfmt != IMGFMT_VAAPI) {
struct mp_image *dst = p->swdec_surfaces[p->output_surface];
if (!dst || va_surface_upload(p, dst, mpi) < 0) {
MP_WARN(vo, "Could not upload surface.\n");
talloc_free(mpi);
return;
}
mp_image_copy_attributes(dst, mpi);
talloc_free(mpi);
mpi = mp_image_new_ref(dst);
}

talloc_free(p->output_surfaces[p->output_surface]);
p->output_surfaces[p->output_surface] = mpi;
if (mpi) {
talloc_free(p->output_surfaces[p->output_surface]);
p->output_surfaces[p->output_surface] = mpi;
}

draw_osd(vo);
}
Expand Down Expand Up @@ -715,10 +717,6 @@ static int control(struct vo *vo, uint32_t request, void *data)
struct priv *p = vo->priv;

switch (request) {
case VOCTRL_REDRAW_FRAME:
p->output_surface = p->visible_surface;
draw_osd(vo);
return true;
case VOCTRL_SET_PANSCAN:
resize(p);
return VO_TRUE;
Expand Down Expand Up @@ -858,7 +856,7 @@ const struct vo_driver video_out_vaapi = {
.query_format = query_format,
.reconfig = reconfig,
.control = control,
.draw_image = draw_image,
.draw_frame = draw_frame,
.flip_page = flip_page,
.get_vsync = get_vsync,
.wakeup = vo_x11_wakeup,
Expand Down
Loading

0 comments on commit b39c3d1

Please sign in to comment.