summaryrefslogtreecommitdiffstats
path: root/video/out/opengl/hwdec_osx.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_osx.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_osx.c')
-rw-r--r--video/out/opengl/hwdec_osx.c35
1 files changed, 17 insertions, 18 deletions
diff --git a/video/out/opengl/hwdec_osx.c b/video/out/opengl/hwdec_osx.c
index 5aa4d3dcd4..2c1ffc71ae 100644
--- a/video/out/opengl/hwdec_osx.c
+++ b/video/out/opengl/hwdec_osx.c
@@ -33,6 +33,7 @@ struct vt_gl_plane_format {
GLenum gl_format;
GLenum gl_type;
GLenum gl_internal_format;
+ char swizzle[5];
};
struct vt_format {
@@ -65,7 +66,7 @@ static struct vt_format vt_formats[] = {
.imgfmt = IMGFMT_UYVY,
.planes = 1,
.gl = {
- { GL_RGB_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, GL_RGB }
+ { GL_RGB_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, GL_RGB, "gbra" }
}
},
{
@@ -163,14 +164,8 @@ static int create(struct gl_hwdec *hw)
return -1;
struct priv *p = talloc_zero(hw, struct priv);
- struct vt_format *f = vt_get_gl_format_from_imgfmt(IMGFMT_NV12);
- if (!f)
- return -1;
-
hw->priv = p;
- hw->converted_imgfmt = f->imgfmt;
- hw->gl_texture_target = GL_TEXTURE_RECTANGLE;
hw->gl->GenTextures(MP_MAX_PLANES, p->gl_planes);
p->vtctx = (struct mp_vt_ctx){
@@ -197,16 +192,13 @@ static int reinit(struct gl_hwdec *hw, struct mp_image_params *params)
return -1;
}
- hw->converted_imgfmt = f->imgfmt;
+ params->imgfmt = f->imgfmt;
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)
{
- if (!check_hwdec(hw))
- return -1;
-
struct priv *p = hw->priv;
GL *gl = hw->gl;
@@ -230,11 +222,13 @@ static int map_image(struct gl_hwdec *hw, struct mp_image *hw_image,
const int planes = CVPixelBufferGetPlaneCount(p->pbuf);
assert(planar && planes == f->planes || f->planes == 1);
+ GLenum gl_target = GL_TEXTURE_RECTANGLE;
+
for (int i = 0; i < f->planes; i++) {
- gl->BindTexture(hw->gl_texture_target, p->gl_planes[i]);
+ gl->BindTexture(gl_target, p->gl_planes[i]);
CGLError err = CGLTexImageIOSurface2D(
- CGLGetCurrentContext(), hw->gl_texture_target,
+ CGLGetCurrentContext(), gl_target,
f->gl[i].gl_internal_format,
IOSurfaceGetWidthOfPlane(surface, i),
IOSurfaceGetHeightOfPlane(surface, i),
@@ -244,9 +238,14 @@ static int map_image(struct gl_hwdec *hw, struct mp_image *hw_image,
MP_ERR(hw, "error creating IOSurface texture for plane %d: %s (%x)\n",
i, CGLErrorString(err), gl->GetError());
- gl->BindTexture(hw->gl_texture_target, 0);
+ gl->BindTexture(gl_target, 0);
- out_textures[i] = p->gl_planes[i];
+ out_frame->planes[i] = (struct gl_hwdec_plane){
+ .gl_texture = p->gl_planes[i],
+ .gl_target = gl_target,
+ .tex_w = IOSurfaceGetWidthOfPlane(surface, i),
+ .tex_h = IOSurfaceGetHeightOfPlane(surface, i),
+ };
}
return 0;
@@ -269,6 +268,6 @@ const struct gl_hwdec_driver gl_hwdec_videotoolbox = {
.imgfmt = IMGFMT_VIDEOTOOLBOX,
.create = create,
.reinit = reinit,
- .map_image = map_image,
+ .map_frame = map_frame,
.destroy = destroy,
};