summaryrefslogtreecommitdiffstats
path: root/video/out/opengl/hwdec_cuda.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-02-17 16:39:10 +0100
committerwm4 <wm4@nowhere>2017-02-17 16:39:10 +0100
commit91a2ddfdd775a4db02c6fe32d7c348a479bb5d9e (patch)
treedc5245b7f21f6fdf48a0d7f43325e60cac8227aa /video/out/opengl/hwdec_cuda.c
parenteda69f5333a012dd76f8a9a46baa0e4624e95290 (diff)
downloadmpv-91a2ddfdd775a4db02c6fe32d7c348a479bb5d9e.tar.bz2
mpv-91a2ddfdd775a4db02c6fe32d7c348a479bb5d9e.tar.xz
vo_opengl: hwdec_cuda: use new format setup function
Gives us automatically support for all formats vo_opengl supports.
Diffstat (limited to 'video/out/opengl/hwdec_cuda.c')
-rw-r--r--video/out/opengl/hwdec_cuda.c42
1 files changed, 8 insertions, 34 deletions
diff --git a/video/out/opengl/hwdec_cuda.c b/video/out/opengl/hwdec_cuda.c
index 40c4e19041..e64de97fd3 100644
--- a/video/out/opengl/hwdec_cuda.c
+++ b/video/out/opengl/hwdec_cuda.c
@@ -42,8 +42,7 @@ struct priv {
GLuint gl_textures[4];
CUgraphicsResource cu_res[4];
CUarray cu_array[4];
- int sample_count[4];
- int sample_width;
+ int plane_bytes[4];
CUcontext cuda_ctx;
};
@@ -157,27 +156,8 @@ static int reinit(struct gl_hwdec *hw, struct mp_image_params *params)
mp_image_set_params(&p->layout, params);
- for (int n = 0; n < 4; n++)
- p->sample_count[n] = 0;
-
- switch (params->imgfmt) {
- case IMGFMT_NV12:
- p->sample_width = 1;
- p->sample_count[0] = 1;
- p->sample_count[1] = 2;
- break;
- case IMGFMT_P010:
- case IMGFMT_P016:
- p->sample_width = 2;
- p->sample_count[0] = 1;
- p->sample_count[1] = 2;
- break;
- case IMGFMT_420P:
- p->sample_width = 1;
- for (int n = 0; n < 3; n++)
- p->sample_count[n] = 1;
- break;
- default:
+ struct gl_imgfmt_desc desc;
+ if (!gl_get_imgfmt_desc(gl, params->imgfmt, &desc)) {
MP_ERR(hw, "Unsupported format: %s\n", mp_imgfmt_to_name(params->imgfmt));
return -1;
}
@@ -187,12 +167,10 @@ static int reinit(struct gl_hwdec *hw, struct mp_image_params *params)
return ret;
gl->GenTextures(4, p->gl_textures);
- for (int n = 0; n < 4; n++) {
- if (!p->sample_count[n])
- break;
+ for (int n = 0; n < desc.num_planes; n++) {
+ const struct gl_format *fmt = desc.planes[n];
- const struct gl_format *fmt =
- gl_find_unorm_format(gl, p->sample_width, p->sample_count[n]);
+ p->plane_bytes[n] = gl_bytes_per_pixel(fmt->format, fmt->type);
gl->BindTexture(GL_TEXTURE_2D, p->gl_textures[n]);
GLenum filter = GL_NEAREST;
@@ -270,10 +248,7 @@ static int map_frame(struct gl_hwdec *hw, struct mp_image *hw_image,
*out_frame = (struct gl_hwdec_frame) { 0, };
- for (int n = 0; n < 4; n++) {
- if (!p->sample_count[n])
- break;
-
+ for (int n = 0; n < p->layout.num_planes; n++) {
// widthInBytes must account for the chroma plane
// elements being two samples wide.
CUDA_MEMCPY2D cpy = {
@@ -283,8 +258,7 @@ static int map_frame(struct gl_hwdec *hw, struct mp_image *hw_image,
.srcPitch = hw_image->stride[n],
.srcY = 0,
.dstArray = p->cu_array[n],
- .WidthInBytes = mp_image_plane_w(&p->layout, n) *
- p->sample_count[n] * p->sample_width,
+ .WidthInBytes = mp_image_plane_w(&p->layout, n) * p->plane_bytes[n],
.Height = mp_image_plane_h(&p->layout, n),
};
ret = CHECK_CU(cuMemcpy2D(&cpy));