summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-12-22 17:50:15 +0100
committerwm4 <wm4@nowhere>2013-01-13 20:04:12 +0100
commit3d6d549dac2aa06ecd07bb04902f55140661ace3 (patch)
tree80d548014a2363fe236ca061c87282a5c05ee8c2 /video
parent1c65428d6f70f05333ecc8284e3f235c679fff26 (diff)
downloadmpv-3d6d549dac2aa06ecd07bb04902f55140661ace3.tar.bz2
mpv-3d6d549dac2aa06ecd07bb04902f55140661ace3.tar.xz
vo_xv, vo_x11: simplify OSD redrawing
In order to support OSD redrawing for vo_xv and vo_x11, draw_bmp.c included an awkward "backup" mechanism to copy and restore image regions that have been changed by OSD/subtitles. Replace this by a much simpler mechanism: keep a reference to the original image, and use that to restore the Xv/X framebuffers. In the worst case, this may increase cache pressure and memory usage, even if no OSD or subtitles are rendered. In practice, it seems to be always faster.
Diffstat (limited to 'video')
-rw-r--r--video/out/vo_x11.c41
-rw-r--r--video/out/vo_xv.c27
2 files changed, 38 insertions, 30 deletions
diff --git a/video/out/vo_x11.c b/video/out/vo_x11.c
index 8b41a7afc3..c45dac5bdd 100644
--- a/video/out/vo_x11.c
+++ b/video/out/vo_x11.c
@@ -55,7 +55,7 @@ extern int sws_flags;
struct priv {
struct vo *vo;
- struct mp_draw_sub_backup *osd_backup;
+ struct mp_image *original_image;
/* local data */
unsigned char *ImageData;
@@ -268,6 +268,8 @@ static int config(struct vo *vo, uint32_t width, uint32_t height,
Colormap theCmap;
const struct fmt2Xfmtentry_s *fmte = fmt2Xfmt;
+ mp_image_unrefp(&p->original_image);
+
#ifdef CONFIG_XF86VM
int vm = flags & VOFLAG_MODESWITCHING;
#endif
@@ -441,30 +443,21 @@ static void draw_osd(struct vo *vo, struct osd_state *osd)
.video_par = vo->aspdat.par,
};
- osd_draw_on_image_bk(osd, res, osd->vo_pts, 0, p->osd_backup, &img);
+ osd_draw_on_image(osd, res, osd->vo_pts, 0, &img);
}
static mp_image_t *get_screenshot(struct vo *vo)
{
struct priv *p = vo->priv;
- struct mp_image img = get_x_buffer(p);
- struct mp_image *res = mp_image_new_copy(&img);
- mp_draw_sub_backup_restore(p->osd_backup, res);
+ if (!p->original_image)
+ return NULL;
+ struct mp_image *res = mp_image_new_ref(p->original_image);
+ mp_image_set_display_size(res, vo->aspdat.prew, vo->aspdat.preh);
return res;
}
-static int redraw_frame(struct vo *vo)
-{
- struct priv *p = vo->priv;
-
- struct mp_image img = get_x_buffer(p);
- mp_draw_sub_backup_restore(p->osd_backup, &img);
-
- return true;
-}
-
static void flip_page(struct vo *vo)
{
struct priv *p = vo->priv;
@@ -516,7 +509,19 @@ static void draw_image(struct vo *vo, mp_image_t *mpi)
}
sws_scale(p->swsContext, (const uint8_t **)mpi->planes, mpi->stride,
0, mpi->h, dst, dstStride);
- mp_draw_sub_backup_reset(p->osd_backup);
+
+ mp_image_setrefp(&p->original_image, mpi);
+}
+
+static int redraw_frame(struct vo *vo)
+{
+ struct priv *p = vo->priv;
+
+ if (!p->original_image)
+ return false;
+
+ draw_image(vo, p->original_image);
+ return true;
}
static int query_format(struct vo *vo, uint32_t format)
@@ -551,6 +556,8 @@ static void uninit(struct vo *vo)
if (p->myximage)
freeMyXImage(p);
+ talloc_free(p->original_image);
+
#ifdef CONFIG_XF86VM
vo_vm_close(vo);
#endif
@@ -571,8 +578,6 @@ static int preinit(struct vo *vo, const char *arg)
return ENOSYS;
}
- p->osd_backup = talloc_steal(p, mp_draw_sub_backup_new());
-
if (!vo_init(vo))
return -1; // Can't open X11
return 0;
diff --git a/video/out/vo_xv.c b/video/out/vo_xv.c
index dc7f805e4b..7a454e33c4 100644
--- a/video/out/vo_xv.c
+++ b/video/out/vo_xv.c
@@ -73,7 +73,7 @@ struct xvctx {
int total_buffers;
int visible_buf;
XvImage *xvimage[2];
- struct mp_draw_sub_backup *osd_backup;
+ struct mp_image *original_image;
uint32_t image_width;
uint32_t image_height;
uint32_t image_format;
@@ -159,6 +159,8 @@ static int config(struct vo *vo, uint32_t width, uint32_t height,
struct xvctx *ctx = vo->priv;
int i;
+ mp_image_unrefp(&ctx->original_image);
+
ctx->image_height = height;
ctx->image_width = width;
ctx->image_format = format;
@@ -383,17 +385,19 @@ static void draw_osd(struct vo *vo, struct osd_state *osd)
.video_par = vo->aspdat.par,
};
- osd_draw_on_image_bk(osd, res, osd->vo_pts, 0, ctx->osd_backup, &img);
+ osd_draw_on_image(osd, res, osd->vo_pts, 0, &img);
}
static int redraw_frame(struct vo *vo)
{
struct xvctx *ctx = vo->priv;
+ if (!ctx->original_image)
+ return false;
+
struct mp_image img = get_xv_buffer(vo, ctx->visible_buf);
- mp_draw_sub_backup_restore(ctx->osd_backup, &img);
+ mp_image_copy(&img, ctx->original_image);
ctx->current_buf = ctx->visible_buf;
-
return true;
}
@@ -414,12 +418,11 @@ static mp_image_t *get_screenshot(struct vo *vo)
{
struct xvctx *ctx = vo->priv;
- struct mp_image img = get_xv_buffer(vo, ctx->visible_buf);
- struct mp_image *res = mp_image_new_copy(&img);
- mp_image_set_display_size(res, vo->aspdat.prew, vo->aspdat.preh);
- // try to get an image without OSD
- mp_draw_sub_backup_restore(ctx->osd_backup, res);
+ if (!ctx->original_image)
+ return NULL;
+ struct mp_image *res = mp_image_new_ref(ctx->original_image);
+ mp_image_set_display_size(res, vo->aspdat.prew, vo->aspdat.preh);
return res;
}
@@ -430,7 +433,7 @@ static void draw_image(struct vo *vo, mp_image_t *mpi)
struct mp_image xv_buffer = get_xv_buffer(vo, ctx->current_buf);
mp_image_copy(&xv_buffer, mpi);
- mp_draw_sub_backup_reset(ctx->osd_backup);
+ mp_image_setrefp(&ctx->original_image, mpi);
}
static int query_format(struct vo *vo, uint32_t format)
@@ -454,6 +457,8 @@ static void uninit(struct vo *vo)
struct xvctx *ctx = vo->priv;
int i;
+ talloc_free(ctx->original_image);
+
ctx->visible_buf = -1;
if (ctx->ai)
XvFreeAdaptorInfo(ctx->ai);
@@ -595,8 +600,6 @@ static int preinit(struct vo *vo, const char *arg)
ctx->fo = XvListImageFormats(x11->display, x11->xv_port,
(int *) &ctx->formats);
- ctx->osd_backup = talloc_steal(ctx, mp_draw_sub_backup_new());
-
return 0;
error: