summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-07-03 19:29:43 +0200
committerwm4 <wm4@nowhere>2016-07-03 19:32:43 +0200
commit8ed32e90c933c13ce128f1edf44624616f8efca0 (patch)
tree5319ac480b71317e2952ae0a4d12ac9b71d71e7d
parent37cf92c07a7d664907ede87e9464680cc36bd5ec (diff)
downloadmpv-8ed32e90c933c13ce128f1edf44624616f8efca0.tar.bz2
mpv-8ed32e90c933c13ce128f1edf44624616f8efca0.tar.xz
sub: move RGBA scaling to vo_vaapi
vo_vaapi is the only thing which can't scale RGBA on the GPU. (Other cases of RGBA scaling are handled in draw_bmp.c for some reason.) Move this code and get rid of the osd_conv_cache thing. Functionally, nothing changes.
-rw-r--r--sub/img_convert.c62
-rw-r--r--sub/img_convert.h4
-rw-r--r--video/out/vo_vaapi.c32
3 files changed, 25 insertions, 73 deletions
diff --git a/sub/img_convert.c b/sub/img_convert.c
index e49b7785af..0ce5c7ac0a 100644
--- a/sub/img_convert.c
+++ b/sub/img_convert.c
@@ -30,17 +30,6 @@
#include "video/mp_image.h"
#include "video/sws_utils.h"
-struct osd_conv_cache {
- struct sub_bitmap part[MP_SUB_BB_LIST_MAX];
- struct sub_bitmap *parts;
- void *scratch;
-};
-
-struct osd_conv_cache *osd_conv_cache_new(void)
-{
- return talloc_zero(NULL, struct osd_conv_cache);
-}
-
void mp_blur_rgba_sub_bitmap(struct sub_bitmap *d, double gblur)
{
struct mp_image *tmp1 = mp_image_alloc(IMGFMT_BGRA, d->w, d->h);
@@ -58,57 +47,6 @@ void mp_blur_rgba_sub_bitmap(struct sub_bitmap *d, double gblur)
talloc_free(tmp1);
}
-// If RGBA parts need scaling, scale them.
-bool osd_scale_rgba(struct osd_conv_cache *c, struct sub_bitmaps *imgs)
-{
- struct sub_bitmaps src = *imgs;
- if (src.format != SUBBITMAP_RGBA)
- return false;
-
- bool need_scale = false;
- for (int n = 0; n < src.num_parts; n++) {
- struct sub_bitmap *sb = &src.parts[n];
- if (sb->w != sb->dw || sb->h != sb->dh)
- need_scale = true;
- }
- if (!need_scale)
- return false;
-
- 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.
- for (int n = 0; n < src.num_parts; n++) {
- struct sub_bitmap *d = &imgs->parts[n];
- struct sub_bitmap *s = &src.parts[n];
-
- struct mp_image src_image = {0};
- mp_image_setfmt(&src_image, IMGFMT_BGRA);
- mp_image_set_size(&src_image, s->w, s->h);
- src_image.planes[0] = s->bitmap;
- src_image.stride[0] = s->stride;
-
- d->x = s->x;
- d->y = s->y;
- d->w = d->dw = s->dw;
- d->h = d->dh = s->dh;
- struct mp_image *image = mp_image_alloc(IMGFMT_BGRA, d->w, d->h);
- talloc_steal(c->parts, image);
- if (image) {
- d->stride = image->stride[0];
- d->bitmap = image->planes[0];
-
- mp_image_swscale(image, &src_image, mp_sws_fast_flags);
- } else {
- // on OOM, skip the region; just don't scale it
- *d = *s;
- }
- }
- return true;
-}
-
bool mp_sub_bitmaps_bb(struct sub_bitmaps *imgs, struct mp_rect *out_bb)
{
struct mp_rect bb = {INT_MAX, INT_MAX, INT_MIN, INT_MIN};
diff --git a/sub/img_convert.h b/sub/img_convert.h
index bf228a1f65..e03c155f46 100644
--- a/sub/img_convert.h
+++ b/sub/img_convert.h
@@ -3,16 +3,12 @@
#include <stdbool.h>
-struct osd_conv_cache;
struct sub_bitmaps;
struct sub_bitmap;
struct mp_rect;
-struct osd_conv_cache *osd_conv_cache_new(void);
-
// Sub postprocessing
void mp_blur_rgba_sub_bitmap(struct sub_bitmap *d, double gblur);
-bool osd_scale_rgba(struct osd_conv_cache *c, struct sub_bitmaps *imgs);
bool mp_sub_bitmaps_bb(struct sub_bitmaps *imgs, struct mp_rect *out_bb);
diff --git a/video/out/vo_vaapi.c b/video/out/vo_vaapi.c
index dc8aaacf9e..8380771e27 100644
--- a/video/out/vo_vaapi.c
+++ b/video/out/vo_vaapi.c
@@ -32,8 +32,9 @@
#include "common/msg.h"
#include "video/out/vo.h"
#include "video/mp_image_pool.h"
-#include "sub/osd.h"
+#include "video/sws_utils.h"
#include "sub/img_convert.h"
+#include "sub/osd.h"
#include "x11_common.h"
#include "video/mp_image.h"
@@ -58,7 +59,6 @@ struct vaapi_osd_part {
int change_id;
struct vaapi_osd_image image;
struct vaapi_subpic subpic;
- struct osd_conv_cache *conv_cache;
};
#define MAX_OUTPUT_SURFACES 2
@@ -336,8 +336,6 @@ static void draw_osd_cb(void *pctx, struct sub_bitmaps *imgs)
if (imgs->change_id != part->change_id) {
part->change_id = imgs->change_id;
- osd_scale_rgba(part->conv_cache, imgs);
-
struct mp_rect bb;
if (!mp_sub_bitmaps_bb(imgs, &bb))
goto error;
@@ -365,6 +363,25 @@ static void draw_osd_cb(void *pctx, struct sub_bitmaps *imgs)
for (int n = 0; n < imgs->num_parts; n++) {
struct sub_bitmap *sub = &imgs->parts[n];
+ struct mp_image src = {0};
+ mp_image_setfmt(&src, IMGFMT_BGRA);
+ mp_image_set_size(&src, sub->w, sub->h);
+ src.planes[0] = sub->bitmap;
+ src.stride[0] = sub->stride;
+
+ struct mp_image *bmp = &src;
+
+ struct mp_image *tmp = NULL;
+ if (sub->dw != sub->w || sub->dh != sub->h) {
+ tmp = mp_image_alloc(IMGFMT_BGRA, sub->dw, sub->dh);
+ if (!tmp)
+ goto error;
+
+ mp_image_swscale(tmp, &src, mp_sws_fast_flags);
+
+ bmp = tmp;
+ }
+
// Note: nothing guarantees that the sub-bitmaps don't overlap.
// But in all currently existing cases, they don't.
// We simply hope that this won't change, and nobody will
@@ -373,8 +390,10 @@ static void draw_osd_cb(void *pctx, struct sub_bitmaps *imgs)
size_t dst = (sub->y - bb.y0) * vaimg.stride[0] +
(sub->x - bb.x0) * 4;
- memcpy_pic(vaimg.planes[0] + dst, sub->bitmap, sub->w * 4, sub->h,
- vaimg.stride[0], sub->stride);
+ memcpy_pic(vaimg.planes[0] + dst, bmp->planes[0], sub->dw * 4,
+ sub->dh, vaimg.stride[0], bmp->stride[0]);
+
+ talloc_free(tmp);
}
if (!va_image_unmap(p->mpvaapi, &img->image))
@@ -630,7 +649,6 @@ static int preinit(struct vo *vo)
struct vaapi_osd_part *part = &p->osd_parts[n];
part->image.image.image_id = VA_INVALID_ID;
part->image.subpic_id = VA_INVALID_ID;
- part->conv_cache = talloc_steal(vo, osd_conv_cache_new());
}
int max_display_attrs = vaMaxNumDisplayAttributes(p->display);