summaryrefslogtreecommitdiffstats
path: root/sub
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 /sub
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 'sub')
-rw-r--r--sub/draw_bmp.c123
-rw-r--r--sub/draw_bmp.h8
-rw-r--r--sub/sub.c14
-rw-r--r--sub/sub.h5
4 files changed, 1 insertions, 149 deletions
diff --git a/sub/draw_bmp.c b/sub/draw_bmp.c
index 23e05464cc..64a12a2da5 100644
--- a/sub/draw_bmp.c
+++ b/sub/draw_bmp.c
@@ -512,127 +512,4 @@ void mp_draw_sub_bitmaps(struct mp_draw_sub_cache **cache, struct mp_image *dst,
}
}
-struct mp_draw_sub_backup
-{
- bool valid;
- struct mp_image *image; // backed up image parts
- struct line_ext *lines[MP_MAX_PLANES]; // backup range for each line
-};
-
-struct line_ext {
- int x0, x1; // x1 is exclusive
-};
-
-struct mp_draw_sub_backup *mp_draw_sub_backup_new(void)
-{
- return talloc_zero(NULL, struct mp_draw_sub_backup);
-}
-
-// Signal that the full image is valid (nothing to backup).
-void mp_draw_sub_backup_reset(struct mp_draw_sub_backup *backup)
-{
- backup->valid = true;
- if (backup->image) {
- for (int p = 0; p < MP_MAX_PLANES; p++) {
- int h = backup->image->h;
- for (int y = 0; y < h; y++) {
- struct line_ext *ext = &backup->lines[p][y];
- ext->x0 = ext->x1 = -1;
- }
- }
- }
-}
-
-static void backup_realloc(struct mp_draw_sub_backup *backup,
- struct mp_image *img)
-{
- if (backup->image && backup->image->imgfmt == img->imgfmt
- && backup->image->w == img->w && backup->image->h == img->h)
- return;
-
- talloc_free_children(backup);
- backup->image = mp_image_alloc(img->imgfmt, img->w, img->h);
- talloc_steal(backup, backup->image);
- for (int p = 0; p < MP_MAX_PLANES; p++) {
- backup->lines[p] = talloc_array(backup, struct line_ext,
- backup->image->h);
- }
- mp_draw_sub_backup_reset(backup);
-}
-
-static void copy_line(struct mp_image *dst, struct mp_image *src,
- int p, int plane_y, int x0, int x1)
-{
- int bits = dst->fmt.bpp[p];
- int xs = p ? dst->chroma_x_shift : 0;
- memcpy(dst->planes[p] + plane_y * dst->stride[p] + (x0 >> xs) * bits / 8,
- src->planes[p] + plane_y * src->stride[p] + (x0 >> xs) * bits / 8,
- ((x1 - x0) >> xs) * bits / 8);
-}
-
-static void backup_rect(struct mp_draw_sub_backup *backup, struct mp_image *img,
- int plane, struct mp_rect rc)
-{
- if (!align_bbox_for_swscale(img, &rc))
- return;
- int ys = plane ? img->chroma_y_shift : 0;
- int yp = ys ? ((1 << ys) - 1) : 0;
- for (int y = (rc.y0 >> ys); y < ((rc.y1 + yp) >> ys); y++) {
- struct line_ext *ext = &backup->lines[plane][y];
- if (ext->x0 == -1) {
- copy_line(backup->image, img, plane, y, rc.x0, rc.x1);
- ext->x0 = rc.x0;
- ext->x1 = rc.x1;
- } else {
- if (rc.x0 < ext->x0) {
- copy_line(backup->image, img, plane, y, rc.x0, ext->x0);
- ext->x0 = rc.x0;
- }
- if (ext->x1 < rc.x1) {
- copy_line(backup->image, img, plane, y, ext->x1, rc.x1);
- ext->x1 = rc.x1;
- }
- }
- }
-}
-
-void mp_draw_sub_backup_add(struct mp_draw_sub_backup *backup,
- struct mp_image *img, struct sub_bitmaps *sbs)
-{
- backup_realloc(backup, img);
-
- for (int p = 0; p < img->num_planes; p++) {
- for (int i = 0; i < sbs->num_parts; ++i) {
- struct sub_bitmap *sb = &sbs->parts[i];
- struct mp_rect rc = {sb->x, sb->y, sb->x + sb->dw, sb->y + sb->dh};
- backup_rect(backup, img, p, rc);
- }
- }
-}
-
-bool mp_draw_sub_backup_restore(struct mp_draw_sub_backup *backup,
- struct mp_image *buffer)
-{
- if (!backup->image || backup->image->imgfmt != buffer->imgfmt
- || backup->image->w != buffer->w || backup->image->h != buffer->h
- || !backup->valid)
- {
- backup->valid = false;
- return false;
- }
- struct mp_image *img = backup->image;
- for (int p = 0; p < img->num_planes; p++) {
- int ys = p ? img->chroma_y_shift : 0;
- int yp = ys ? ((1 << ys) - 1) : 0;
- int p_h = ((img->h + yp) >> ys);
- for (int y = 0; y < p_h; y++) {
- struct line_ext *ext = &backup->lines[p][y];
- if (ext->x0 < ext->x1) {
- copy_line(buffer, img, p, y, ext->x0, ext->x1);
- }
- }
- }
- return true;
-}
-
// vim: ts=4 sw=4 et tw=80
diff --git a/sub/draw_bmp.h b/sub/draw_bmp.h
index 2eae68b58c..489e91f666 100644
--- a/sub/draw_bmp.h
+++ b/sub/draw_bmp.h
@@ -12,14 +12,6 @@ void mp_draw_sub_bitmaps(struct mp_draw_sub_cache **cache, struct mp_image *dst,
extern const bool mp_draw_sub_formats[SUBBITMAP_COUNT];
-struct mp_draw_sub_backup;
-struct mp_draw_sub_backup *mp_draw_sub_backup_new(void);
-void mp_draw_sub_backup_add(struct mp_draw_sub_backup *backup,
- struct mp_image *img, struct sub_bitmaps *sbs);
-void mp_draw_sub_backup_reset(struct mp_draw_sub_backup *backup);
-bool mp_draw_sub_backup_restore(struct mp_draw_sub_backup *backup,
- struct mp_image *buffer);
-
#endif /* MPLAYER_DRAW_BMP_H */
// vim: ts=4 sw=4 et tw=80
diff --git a/sub/sub.c b/sub/sub.c
index 4baf4f1487..ea9c51a758 100644
--- a/sub/sub.c
+++ b/sub/sub.c
@@ -275,7 +275,6 @@ void osd_draw(struct osd_state *osd, struct mp_osd_res res,
struct draw_on_image_closure {
struct osd_state *osd;
struct mp_image *dest;
- struct mp_draw_sub_backup *bk;
struct mp_image_pool *pool;
bool changed;
};
@@ -284,8 +283,6 @@ static void draw_on_image(void *ctx, struct sub_bitmaps *imgs)
{
struct draw_on_image_closure *closure = ctx;
struct osd_state *osd = closure->osd;
- if (closure->bk)
- mp_draw_sub_backup_add(closure->bk, closure->dest, imgs);
if (closure->pool) {
mp_image_pool_make_writeable(closure->pool, closure->dest);
} else {
@@ -314,16 +311,7 @@ void osd_draw_on_image_p(struct osd_state *osd, struct mp_osd_res res,
double video_pts, int draw_flags,
struct mp_image_pool *pool, struct mp_image *dest)
{
- struct draw_on_image_closure closure = {osd, dest, .pool = pool};
- osd_draw(osd, res, video_pts, draw_flags, mp_draw_sub_formats,
- &draw_on_image, &closure);
-}
-
-void osd_draw_on_image_bk(struct osd_state *osd, struct mp_osd_res res,
- double video_pts, int draw_flags,
- struct mp_draw_sub_backup *bk, struct mp_image *dest)
-{
- struct draw_on_image_closure closure = {osd, dest, bk};
+ struct draw_on_image_closure closure = {osd, dest, pool};
osd_draw(osd, res, video_pts, draw_flags, mp_draw_sub_formats,
&draw_on_image, &closure);
}
diff --git a/sub/sub.h b/sub/sub.h
index 38b7b29f34..c7f8a8b022 100644
--- a/sub/sub.h
+++ b/sub/sub.h
@@ -227,11 +227,6 @@ void osd_draw_on_image_p(struct osd_state *osd, struct mp_osd_res res,
double video_pts, int draw_flags,
struct mp_image_pool *pool, struct mp_image *dest);
-struct mp_draw_sub_backup;
-void osd_draw_on_image_bk(struct osd_state *osd, struct mp_osd_res res,
- double video_pts, int draw_flags,
- struct mp_draw_sub_backup *bk, struct mp_image *dest);
-
struct mp_rect;
bool sub_bitmaps_bb(struct sub_bitmaps *imgs, struct mp_rect *out_bb);