summaryrefslogtreecommitdiffstats
path: root/sub
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-06-17 23:11:05 +0200
committerwm4 <wm4@nowhere>2016-06-17 23:15:50 +0200
commit8e6704acdbe020aacc71dbe15981651d6bcca25e (patch)
tree3753cae43c0ed60f60cf2e36c65acb637cb95afc /sub
parent28c7dec157d8d1d7f2945fa3bf9c0b1457faec4d (diff)
downloadmpv-8e6704acdbe020aacc71dbe15981651d6bcca25e.tar.bz2
mpv-8e6704acdbe020aacc71dbe15981651d6bcca25e.tar.xz
sub, vo_opengl: use packed sub-bitmaps directly if available
The previous few commits changed sd_lavc.c's output to packed RGB sub- images. In particular, this means all sub-bitmaps are part of a larger, single bitmap. Change the vo_opengl OSD code such that it can make use of this, and upload the pre-packed image, instead of packing and copying them again. This complicates the upload code a bit (4 code paths due to messy PBO handling). The plan is to make sub-bitmaps always packed, but some more work is required to reach this point. The plan is to pack libass images as well. Since this implies a copy, this will make it easy to refcount the result. (This is all targeted towards vo_opengl. Other VOs, vo_xv, vo_x11, and vo_wayland in particular, will become less efficient. Although at least vo_vdpau and vo_direct3d could be switched to the new method as well.)
Diffstat (limited to 'sub')
-rw-r--r--sub/img_convert.c2
-rw-r--r--sub/osd.h16
-rw-r--r--sub/sd_lavc.c13
3 files changed, 30 insertions, 1 deletions
diff --git a/sub/img_convert.c b/sub/img_convert.c
index 2015e49ca6..348811e773 100644
--- a/sub/img_convert.c
+++ b/sub/img_convert.c
@@ -80,6 +80,7 @@ bool osd_scale_rgba(struct osd_conv_cache *c, struct sub_bitmaps *imgs)
talloc_free(c->parts);
imgs->parts = c->parts = talloc_array(c, struct sub_bitmap, src.num_parts);
+ imgs->packed = NULL;
// Note: we scale all parts, since most likely all need scaling anyway, and
// to get a proper copy of all data in the imgs list.
@@ -158,6 +159,7 @@ bool osd_conv_ass_to_rgba(struct osd_conv_cache *c, struct sub_bitmaps *imgs)
imgs->format = SUBBITMAP_RGBA;
imgs->parts = c->part;
imgs->num_parts = num_bb;
+ imgs->packed = NULL;
size_t newsize = 0;
for (int n = 0; n < num_bb; n++) {
diff --git a/sub/osd.h b/sub/osd.h
index b50b72c587..7cfc695873 100644
--- a/sub/osd.h
+++ b/sub/osd.h
@@ -42,6 +42,11 @@ struct sub_bitmap {
int x, y;
int dw, dh;
+ // If the containing struct sub_bitmaps has the packed field set, then this
+ // is the position within the source. (Strictly speaking this is redundant
+ // with the bitmap pointer.)
+ int src_x, src_y;
+
struct {
uint32_t color;
} libass;
@@ -60,6 +65,17 @@ struct sub_bitmaps {
struct sub_bitmap *parts;
int num_parts;
+ // Packed representation of the bitmap data. If non-NULL, then the
+ // parts[].bitmap pointer points into the image data here (and stride will
+ // correspond to packed->stride[0]).
+ // SUBBITMAP_RGBA: IMGFMT_BGRA (exact match)
+ // Other formats have this set to NULL.
+ struct mp_image *packed;
+
+ // Bounding box for the packed image. All parts will be within the bounding
+ // box. (The origin of the box is at (0,0).)
+ int packed_w, packed_h;
+
int change_id; // Incremented on each change
};
diff --git a/sub/sd_lavc.c b/sub/sd_lavc.c
index cc72efc54d..b7420d33c6 100644
--- a/sub/sd_lavc.c
+++ b/sub/sd_lavc.c
@@ -44,6 +44,7 @@ struct sub {
struct sub_bitmap *inbitmaps;
int count;
struct mp_image *data;
+ int bound_w, bound_h;
int src_w, src_h;
double pts;
double endpts;
@@ -254,7 +255,10 @@ static void read_sub_bitmaps(struct sd *sd, struct sub *sub)
struct pos bb[2];
packer_get_bb(priv->packer, bb);
- if (!sub->data || sub->data->w < bb[1].x || sub->data->h < bb[1].y) {
+ sub->bound_w = bb[1].x;
+ sub->bound_h = bb[1].y;
+
+ if (!sub->data || sub->data->w < sub->bound_w || sub->data->h < sub->bound_h) {
talloc_free(sub->data);
sub->data = mp_image_alloc(IMGFMT_BGRA, priv->packer->w, priv->packer->h);
if (!sub->data) {
@@ -279,6 +283,8 @@ static void read_sub_bitmaps(struct sd *sd, struct sub *sub)
b->h = r->h;
b->x = r->x;
b->y = r->y;
+ b->src_x = pos.x;
+ b->src_y = pos.y;
b->stride = sub->data->stride[0];
b->bitmap = sub->data->planes[0] + pos.y * b->stride + pos.x * 4;
@@ -307,6 +313,8 @@ static void read_sub_bitmaps(struct sd *sd, struct sub *sub)
}
b->bitmap = (char*)b->bitmap - extend * b->stride - extend * 4;
+ b->src_x -= extend;
+ b->src_y -= extend;
b->x -= extend;
b->y -= extend;
b->w += extend * 2;
@@ -443,6 +451,9 @@ static void get_bitmaps(struct sd *sd, struct mp_osd_res d, double pts,
if (priv->displayed_id != current->id)
res->change_id++;
priv->displayed_id = current->id;
+ res->packed = current->data;
+ res->packed_w = current->bound_w;
+ res->packed_h = current->bound_h;
res->format = SUBBITMAP_RGBA;
double video_par = 0;