summaryrefslogtreecommitdiffstats
path: root/video/out/gpu/video.c
diff options
context:
space:
mode:
authorNiklas Haas <git@haasn.dev>2022-02-27 21:07:58 +0100
committerNiklas Haas <github-daiK1o@haasn.dev>2022-03-03 13:06:05 +0100
commitd4fc44e711aee61b34edb654587d6380abe39b05 (patch)
tree0e159674a73cf831882018476684592efe76a0d8 /video/out/gpu/video.c
parentbb434a60ed801723c8e3becae019352935539e50 (diff)
downloadmpv-d4fc44e711aee61b34edb654587d6380abe39b05.tar.bz2
mpv-d4fc44e711aee61b34edb654587d6380abe39b05.tar.xz
vo_gpu: move hwdec loading code to common helper
So I can reuse it in vo_gpu_next without having to reinvent the wheel. In theory, a lot of the stuff could be made more private inside the hwdec code itself, but for the time being I don't care about refactoring this code, merely sharing it.
Diffstat (limited to 'video/out/gpu/video.c')
-rw-r--r--video/out/gpu/video.c133
1 files changed, 16 insertions, 117 deletions
diff --git a/video/out/gpu/video.c b/video/out/gpu/video.c
index e28a88de5b..e158d3bea9 100644
--- a/video/out/gpu/video.c
+++ b/video/out/gpu/video.c
@@ -281,10 +281,7 @@ struct gl_video {
struct cached_file *files;
int num_files;
- bool hwdec_interop_loading_done;
- struct ra_hwdec **hwdecs;
- int num_hwdecs;
-
+ struct ra_hwdec_ctx hwdec_ctx;
struct ra_hwdec_mapper *hwdec_mapper;
struct ra_hwdec *hwdec_overlay;
bool hwdec_active;
@@ -887,14 +884,7 @@ static void init_video(struct gl_video *p)
{
p->use_integer_conversion = false;
- struct ra_hwdec *hwdec = NULL;
- for (int n = 0; n < p->num_hwdecs; n++) {
- if (ra_hwdec_test_format(p->hwdecs[n], p->image_params.imgfmt)) {
- hwdec = p->hwdecs[n];
- break;
- }
- }
-
+ struct ra_hwdec *hwdec = ra_hwdec_get(&p->hwdec_ctx, p->image_params.imgfmt);
if (hwdec) {
if (hwdec->driver->overlay_frame) {
MP_WARN(p, "Using HW-overlay mode. No GL filtering is performed "
@@ -3930,11 +3920,7 @@ void gl_video_uninit(struct gl_video *p)
return;
uninit_video(p);
-
- for (int n = 0; n < p->num_hwdecs; n++)
- ra_hwdec_uninit(p->hwdecs[n]);
- p->num_hwdecs = 0;
-
+ ra_hwdec_ctx_uninit(&p->hwdec_ctx);
gl_sc_destroy(p->sc);
ra_tex_free(p->ra, &p->lut_3d_texture);
@@ -3989,10 +3975,8 @@ bool gl_video_check_format(struct gl_video *p, int mp_format)
if (ra_get_imgfmt_desc(p->ra, mp_format, &desc) &&
is_imgfmt_desc_supported(p, &desc))
return true;
- for (int n = 0; n < p->num_hwdecs; n++) {
- if (ra_hwdec_test_format(p->hwdecs[n], mp_format))
- return true;
- }
+ if (ra_hwdec_get(&p->hwdec_ctx, mp_format))
+ return true;
return false;
}
@@ -4326,108 +4310,23 @@ struct mp_image *gl_video_get_image(struct gl_video *p, int imgfmt, int w, int h
return res;
}
-static void load_add_hwdec(struct gl_video *p, struct mp_hwdec_devices *devs,
- const struct ra_hwdec_driver *drv, bool is_auto)
-{
- bool needs_loading = true;
- for (int j = 0; j < p->num_hwdecs; j++) {
- const struct ra_hwdec *hwdec = p->hwdecs[j];
- if (hwdec->driver == drv) {
- needs_loading = false;
- break;
- }
- }
- if (!needs_loading) {
- return;
- }
-
- struct ra_hwdec *hwdec =
- ra_hwdec_load_driver(p->ra, p->log, p->global, devs, drv, is_auto);
- if (hwdec)
- MP_TARRAY_APPEND(p, p->hwdecs, p->num_hwdecs, hwdec);
-}
-
-static void load_hwdecs_all(struct gl_video *p, struct mp_hwdec_devices *devs)
-{
- if (!p->hwdec_interop_loading_done) {
- for (int n = 0; ra_hwdec_drivers[n]; n++)
- load_add_hwdec(p, devs, ra_hwdec_drivers[n], true);
- p->hwdec_interop_loading_done = true;
- }
-}
-
-void gl_video_load_hwdecs(struct gl_video *p, struct mp_hwdec_devices *devs,
+void gl_video_init_hwdecs(struct gl_video *p, struct mp_hwdec_devices *devs,
bool load_all_by_default)
{
- /*
- * By default, or if the option value is "auto", we will not pre-emptively
- * load any interops, and instead allow them to be loaded on-demand.
- *
- * If the option value is "no", then no interops will be loaded now, and
- * no interops will be loaded, even if requested later.
- *
- * If the option value is "all", then all interops will be loaded now, and
- * obviously no interops will need to be loaded later.
- *
- * Finally, if a specific interop is requested, it will be loaded now, and
- * no other interop will be loaded, even if requested later.
- */
- char *type = p->opts.hwdec_interop;
- if (!type || !type[0] || strcmp(type, "auto") == 0) {
- if (!load_all_by_default)
- return;
- type = "all";
- }
- if (strcmp(type, "no") == 0) {
- // do nothing, just block further loading
- } else if (strcmp(type, "all") == 0) {
- load_hwdecs_all(p, devs);
- } else {
- for (int n = 0; ra_hwdec_drivers[n]; n++) {
- const struct ra_hwdec_driver *drv = ra_hwdec_drivers[n];
- if (strcmp(type, drv->name) == 0) {
- load_add_hwdec(p, devs, drv, false);
- break;
- }
- }
- }
- p->hwdec_interop_loading_done = true;
+ assert(!p->hwdec_ctx.ra);
+ p->hwdec_ctx = (struct ra_hwdec_ctx) {
+ .log = p->log,
+ .global = p->global,
+ .ra = p->ra,
+ };
+
+ ra_hwdec_ctx_init(&p->hwdec_ctx, devs, p->opts.hwdec_interop, load_all_by_default);
}
void gl_video_load_hwdecs_for_img_fmt(struct gl_video *p,
struct mp_hwdec_devices *devs,
int imgfmt)
{
- if (p->hwdec_interop_loading_done) {
- /*
- * If we previously marked interop loading as done (for reasons
- * discussed above), then do not load any other interops regardless
- * of imgfmt.
- */
- return;
- }
-
- if (imgfmt == IMGFMT_NONE) {
- MP_VERBOSE(p, "Loading hwdec drivers for all formats\n");
- load_hwdecs_all(p, devs);
- return;
- }
-
- MP_VERBOSE(p, "Loading hwdec drivers for format: '%s'\n",
- mp_imgfmt_to_name(imgfmt));
- for (int i = 0; ra_hwdec_drivers[i]; i++) {
- bool matched_fmt = false;
- const struct ra_hwdec_driver *drv = ra_hwdec_drivers[i];
- for (int j = 0; drv->imgfmts[j]; j++) {
- if (imgfmt == drv->imgfmts[j]) {
- matched_fmt = true;
- break;
- }
- }
- if (!matched_fmt) {
- continue;
- }
-
- load_add_hwdec(p, devs, drv, false);
- }
+ assert(p->hwdec_ctx.ra);
+ ra_hwdec_ctx_load_fmt(&p->hwdec_ctx, devs, imgfmt);
}