gl_video: support packed YUV formats with Apple extensions

This adds support for packed YUV formats (YUVY and UYVY) using the extension
GL_APPLE_rgb_422. While supporting this formats on their own is not that
important (considering most video is planar YUV) they are used for
interoperability with IOSurfaces.

Next commit will use this formats to render VDA hardware decoded frames through
IOSurface and OpenGL interoperability.
This commit is contained in:
Stefano Pigozzi 2013-11-13 21:52:34 +01:00
parent cb45ea371f
commit 36eebc231e
4 changed files with 47 additions and 2 deletions

View File

@ -462,6 +462,16 @@ struct gl_functions gl_functions[] = {
{0}
},
},
// Apple Packed YUV Formats
// For gl_hwdec_vda.c
// http://www.opengl.org/registry/specs/APPLE/rgb_422.txt
{
.extension = "GL_APPLE_rgb_422",
.provides = MPGL_CAP_APPLE_RGB_422,
.functions = (struct gl_function[]) {
{0}
},
},
};
#undef FN_OFFS
@ -659,6 +669,7 @@ int glFmt2bpp(GLenum format, GLenum type)
case GL_ALPHA:
return component_size;
case GL_YCBCR_MESA:
case GL_RGB_422_APPLE:
return 2;
case GL_RGB:
case GL_BGR:

View File

@ -88,6 +88,7 @@ enum {
MPGL_CAP_FLOAT_TEX = (1 << 9),
MPGL_CAP_TEX_RG = (1 << 10), // GL_ARB_texture_rg / GL 3.x
MPGL_CAP_VDPAU = (1 << 11), // GL_NV_vdpau_interop
MPGL_CAP_APPLE_RGB_422 = (1 << 12), // GL_APPLE_rgb_422
MPGL_CAP_NO_SW = (1 << 30), // used to block sw. renderers
};

View File

@ -249,6 +249,18 @@
#endif
#endif
#ifndef GL_RGB_422_APPLE
#define GL_RGB_422_APPLE 0x8A1F
#endif
#ifndef UNSIGNED_SHORT_8_8_APPLE
#define UNSIGNED_SHORT_8_8_APPLE 0x85BA
#endif
#ifndef UNSIGNED_SHORT_8_8_APPLE
#define UNSIGNED_SHORT_8_8_APPLE 0x85BB
#endif
#ifndef GL_NV_vdpau_interop
#define GLvdpauSurfaceNV GLintptr
#endif

View File

@ -170,7 +170,7 @@ struct gl_video {
struct mp_imgfmt_desc image_desc;
bool is_yuv, is_rgb;
bool is_yuv, is_rgb, is_packed_yuv;
bool is_linear_rgb;
bool has_alpha;
char color_swizzle[5];
@ -238,6 +238,12 @@ static const struct fmt_entry gl_byte_formats[] = {
{0, GL_RGBA16, GL_RGBA, GL_UNSIGNED_SHORT}, // 4 x 16
};
static const struct fmt_entry gl_apple_formats[] = {
{IMGFMT_UYVY, GL_RGB, GL_RGB_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE},
{IMGFMT_YUYV, GL_RGB, GL_RGB_422_APPLE, GL_UNSIGNED_SHORT_8_8_REV_APPLE},
{0}
};
struct packed_fmt_entry {
int fmt;
int8_t component_size;
@ -872,7 +878,8 @@ static void compile_shaders(struct gl_video *p)
if (p->color_swizzle[0])
shader_def(&header_conv, "USE_COLOR_SWIZZLE", p->color_swizzle);
shader_def_opt(&header_conv, "USE_SWAP_UV", p->image_format == IMGFMT_NV21);
shader_def_opt(&header_conv, "USE_YGRAY", p->is_yuv && p->plane_count == 1);
shader_def_opt(&header_conv, "USE_YGRAY", p->is_yuv && !p->is_packed_yuv
&& p->plane_count == 1);
shader_def_opt(&header_conv, "USE_INPUT_GAMMA", convert_input_gamma);
shader_def_opt(&header_conv, "USE_COLORMATRIX", !p->is_rgb);
shader_def_opt(&header_conv, "USE_CONV_GAMMA", convert_input_to_linear);
@ -2058,6 +2065,20 @@ static bool init_format(int fmt, struct gl_video *init)
}
}
// Packed YUV Apple formats
if (init->gl->mpgl_caps & MPGL_CAP_APPLE_RGB_422) {
for (const struct fmt_entry *e = gl_apple_formats; e->mp_format; e++) {
if (e->mp_format == fmt) {
init->is_packed_yuv = true;
supported = true;
snprintf(init->color_swizzle, sizeof(init->color_swizzle),
"gbra");
plane_format[0] = e;
break;
}
}
}
if (!supported)
return false;