summaryrefslogtreecommitdiffstats
path: root/video/out/opengl/hwdec_vdpau.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-05-10 18:29:10 +0200
committerwm4 <wm4@nowhere>2016-05-10 18:42:42 +0200
commitb0b01aa2509778bb5191892b894e17e657152b2e (patch)
treedd29d48d0790dae122404669e2e1f04add21ca1b /video/out/opengl/hwdec_vdpau.c
parent7e6e47b8c4e2e01a2a5c1af02402772f92416980 (diff)
downloadmpv-b0b01aa2509778bb5191892b894e17e657152b2e.tar.bz2
mpv-b0b01aa2509778bb5191892b894e17e657152b2e.tar.xz
vo_opengl: refactor how hwdec interop exports textures
Rename gl_hwdec_driver.map_image to map_frame, and let it fill out a struct gl_hwdec_frame describing the exact texture layout. This gives more flexibility to what the hwdec interop can export. In particular, it can export strange component orders/permutations and textures with padded size. (The latter originating from cropped video.) The way gl_hwdec_frame works is in the spirit of the rest of the vo_opengl video processing code, which tends to put as much information in immediate state (as part of the dataflow), instead of declaring it globally. To some degree this duplicates the texplane and img_tex structs, but until we somehow unify those, it's better to give the hwdec state its own struct. The fact that changing the hwdec struct would require changes and testing on at least 4 platform/GPU combinations makes duplicating it almost a requirement to avoid pain later. Make gl_hwdec_driver.reinit set the new image format and remove the gl_hwdec.converted_imgfmt field. Likewise, gl_hwdec.gl_texture_target is replaced with gl_hwdec_plane.gl_target. Split out a init_image_desc function from init_format. The latter is not called in the hwdec case at all anymore. Setting up most of struct texplane is also completely separate in the hwdec and normal cases. video.c does not check whether the hwdec "mapped" image format is supported. This should not really happen anyway, and if it does, the hwdec interop backend must fail at creation time, so this is not an issue.
Diffstat (limited to 'video/out/opengl/hwdec_vdpau.c')
-rw-r--r--video/out/opengl/hwdec_vdpau.c36
1 files changed, 26 insertions, 10 deletions
diff --git a/video/out/opengl/hwdec_vdpau.c b/video/out/opengl/hwdec_vdpau.c
index e3b69941bf..7f61134376 100644
--- a/video/out/opengl/hwdec_vdpau.c
+++ b/video/out/opengl/hwdec_vdpau.c
@@ -121,7 +121,6 @@ static int create(struct gl_hwdec *hw)
}
p->ctx->hwctx.driver_name = hw->driver->name;
hwdec_devices_add(hw->devs, &p->ctx->hwctx);
- hw->converted_imgfmt = IMGFMT_RGB0;
return 0;
}
@@ -167,17 +166,17 @@ static int reinit(struct gl_hwdec *hw, struct mp_image_params *params)
glCheckError(gl, hw->log, "After initializing vdpau OpenGL interop");
+ params->imgfmt = IMGFMT_RGB0;
+
return 0;
}
-static int map_image(struct gl_hwdec *hw, struct mp_image *hw_image,
- GLuint *out_textures)
+static int map_frame(struct gl_hwdec *hw, struct mp_image *hw_image,
+ struct gl_hwdec_frame *out_frame)
{
struct priv *p = hw->priv;
GL *gl = hw->gl;
- assert(hw_image && hw_image->imgfmt == IMGFMT_VDPAU);
-
int pe = mp_vdpau_handle_preemption(p->ctx, &p->preemption_counter);
if (pe < 1) {
mark_vdpau_objects_uninitialized(hw);
@@ -190,23 +189,40 @@ static int map_image(struct gl_hwdec *hw, struct mp_image *hw_image,
if (!p->vdpgl_surface)
return -1;
- if (p->mapped)
- gl->VDPAUUnmapSurfacesNV(1, &p->vdpgl_surface);
-
mp_vdpau_mixer_render(p->mixer, NULL, p->vdp_surface, NULL, hw_image, NULL);
gl->VDPAUMapSurfacesNV(1, &p->vdpgl_surface);
p->mapped = true;
- out_textures[0] = p->gl_texture;
+ *out_frame = (struct gl_hwdec_frame){
+ .planes = {
+ {
+ .gl_texture = p->gl_texture,
+ .gl_target = GL_TEXTURE_2D,
+ .tex_w = p->image_params.w,
+ .tex_h = p->image_params.h,
+ },
+ },
+ };
return 0;
}
+static void unmap(struct gl_hwdec *hw)
+{
+ struct priv *p = hw->priv;
+ GL *gl = hw->gl;
+
+ if (p->mapped)
+ gl->VDPAUUnmapSurfacesNV(1, &p->vdpgl_surface);
+ p->mapped = false;
+}
+
const struct gl_hwdec_driver gl_hwdec_vdpau = {
.name = "vdpau-glx",
.api = HWDEC_VDPAU,
.imgfmt = IMGFMT_VDPAU,
.create = create,
.reinit = reinit,
- .map_image = map_image,
+ .map_frame = map_frame,
+ .unmap = unmap,
.destroy = destroy,
};