vlc | branch: master | Romain Vimont <[email protected]> | Wed Dec 18 17:26:09 2019 +0100| [730ba37466bae1aa702c94c14a85bab271a0ee74] | committer: Thomas Guillem
opengl: move interop-specific code to interop.c Move functions related to interops from fragment_shader.c to interop.c. > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=730ba37466bae1aa702c94c14a85bab271a0ee74 --- modules/video_output/Makefile.am | 2 +- modules/video_output/opengl/fragment_shaders.c | 212 ---------------------- modules/video_output/opengl/interop.c | 241 +++++++++++++++++++++++++ 3 files changed, 242 insertions(+), 213 deletions(-) diff --git a/modules/video_output/Makefile.am b/modules/video_output/Makefile.am index 19518616c1..6bccecf006 100644 --- a/modules/video_output/Makefile.am +++ b/modules/video_output/Makefile.am @@ -7,7 +7,7 @@ OPENGL_COMMONSOURCES = video_output/opengl/vout_helper.c \ video_output/opengl/gl_common.h video_output/opengl/interop.h \ video_output/opengl/vout_helper.h video_output/opengl/converter.h \ video_output/opengl/internal.h video_output/opengl/fragment_shaders.c \ - video_output/opengl/interop_sw.c + video_output/opengl/interop.c video_output/opengl/interop_sw.c if HAVE_LIBPLACEBO OPENGL_COMMONSOURCES += video_output/placebo_utils.c video_output/placebo_utils.h endif diff --git a/modules/video_output/opengl/fragment_shaders.c b/modules/video_output/opengl/fragment_shaders.c index ad750ce804..f36518972e 100644 --- a/modules/video_output/opengl/fragment_shaders.c +++ b/modules/video_output/opengl/fragment_shaders.c @@ -37,150 +37,6 @@ #include "internal.h" #include "vout_helper.h" -static int GetTexFormatSize(const opengl_vtable_t *vt, int target, - int tex_format, int tex_internal, int tex_type) -{ - if (!vt->GetTexLevelParameteriv) - return -1; - - GLint tex_param_size; - int mul = 1; - switch (tex_format) - { - case GL_BGRA: - mul = 4; - /* fall through */ - case GL_RED: - case GL_RG: - tex_param_size = GL_TEXTURE_RED_SIZE; - break; - case GL_LUMINANCE: - tex_param_size = GL_TEXTURE_LUMINANCE_SIZE; - break; - default: - return -1; - } - GLuint texture; - - vt->GenTextures(1, &texture); - vt->BindTexture(target, texture); - vt->TexImage2D(target, 0, tex_internal, 64, 64, 0, tex_format, tex_type, NULL); - GLint size = 0; - vt->GetTexLevelParameteriv(target, 0, tex_param_size, &size); - - vt->DeleteTextures(1, &texture); - return size > 0 ? size * mul : size; -} - -static int -interop_yuv_base_init(struct vlc_gl_interop *interop, GLenum tex_target, - vlc_fourcc_t chroma, - const vlc_chroma_description_t *desc) -{ - (void) chroma; - - GLint oneplane_texfmt, oneplane16_texfmt, - twoplanes_texfmt, twoplanes16_texfmt; - - if (vlc_gl_StrHasToken(interop->glexts, "GL_ARB_texture_rg")) - { - oneplane_texfmt = GL_RED; - oneplane16_texfmt = GL_R16; - twoplanes_texfmt = GL_RG; - twoplanes16_texfmt = GL_RG16; - } - else - { - oneplane_texfmt = GL_LUMINANCE; - oneplane16_texfmt = GL_LUMINANCE16; - twoplanes_texfmt = GL_LUMINANCE_ALPHA; - twoplanes16_texfmt = 0; - } - - if (desc->pixel_size == 2) - { - if (GetTexFormatSize(interop->vt, tex_target, oneplane_texfmt, - oneplane16_texfmt, GL_UNSIGNED_SHORT) != 16) - return VLC_EGENERIC; - } - - if (desc->plane_count == 3) - { - GLint internal = 0; - GLenum type = 0; - - if (desc->pixel_size == 1) - { - internal = oneplane_texfmt; - type = GL_UNSIGNED_BYTE; - } - else if (desc->pixel_size == 2) - { - internal = oneplane16_texfmt; - type = GL_UNSIGNED_SHORT; - } - else - return VLC_EGENERIC; - - assert(internal != 0 && type != 0); - - interop->tex_count = 3; - for (unsigned i = 0; i < interop->tex_count; ++i ) - { - interop->texs[i] = (struct vlc_gl_tex_cfg) { - { desc->p[i].w.num, desc->p[i].w.den }, - { desc->p[i].h.num, desc->p[i].h.den }, - internal, oneplane_texfmt, type - }; - } - } - else if (desc->plane_count == 2) - { - interop->tex_count = 2; - - if (desc->pixel_size == 1) - { - interop->texs[0] = (struct vlc_gl_tex_cfg) { - { 1, 1 }, { 1, 1 }, oneplane_texfmt, oneplane_texfmt, - GL_UNSIGNED_BYTE - }; - interop->texs[1] = (struct vlc_gl_tex_cfg) { - { 1, 2 }, { 1, 2 }, twoplanes_texfmt, twoplanes_texfmt, - GL_UNSIGNED_BYTE - }; - } - else if (desc->pixel_size == 2) - { - if (twoplanes16_texfmt == 0 - || GetTexFormatSize(interop->vt, tex_target, twoplanes_texfmt, - twoplanes16_texfmt, GL_UNSIGNED_SHORT) != 16) - return VLC_EGENERIC; - interop->texs[0] = (struct vlc_gl_tex_cfg) { - { 1, 1 }, { 1, 1 }, oneplane16_texfmt, oneplane_texfmt, - GL_UNSIGNED_SHORT - }; - interop->texs[1] = (struct vlc_gl_tex_cfg) { - { 1, 2 }, { 1, 2 }, twoplanes16_texfmt, twoplanes_texfmt, - GL_UNSIGNED_SHORT - }; - } - else - return VLC_EGENERIC; - } - else if (desc->plane_count == 1) - { - /* Y1 U Y2 V fits in R G B A */ - interop->tex_count = 1; - interop->texs[0] = (struct vlc_gl_tex_cfg) { - { 1, 2 }, { 1, 1 }, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE - }; - } - else - return VLC_EGENERIC; - - return VLC_SUCCESS; -} - static int tc_yuv_base_init(opengl_tex_converter_t *tc, vlc_fourcc_t chroma, const vlc_chroma_description_t *desc, @@ -245,36 +101,6 @@ tc_yuv_base_init(opengl_tex_converter_t *tc, vlc_fourcc_t chroma, return VLC_SUCCESS; } -static int -interop_rgb_base_init(struct vlc_gl_interop *interop, GLenum tex_target, - vlc_fourcc_t chroma) -{ - (void) tex_target; - - switch (chroma) - { - case VLC_CODEC_RGB32: - case VLC_CODEC_RGBA: - interop->texs[0] = (struct vlc_gl_tex_cfg) { - { 1, 1 }, { 1, 1 }, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE - }; - break; - case VLC_CODEC_BGRA: { - if (GetTexFormatSize(interop->vt, tex_target, GL_BGRA, GL_RGBA, - GL_UNSIGNED_BYTE) != 32) - return VLC_EGENERIC; - interop->texs[0] = (struct vlc_gl_tex_cfg) { - { 1, 1 }, { 1, 1 }, GL_RGBA, GL_BGRA, GL_UNSIGNED_BYTE - }; - break; - } - default: - return VLC_EGENERIC; - } - interop->tex_count = 1; - return VLC_SUCCESS; -} - static int tc_base_fetch_locations(opengl_tex_converter_t *tc, GLuint program) { @@ -392,16 +218,6 @@ tc_xyz12_prepare_shader(const opengl_tex_converter_t *tc, tc->vt->Uniform1i(tc->uloc.Texture[0], 0); } -static void -interop_xyz12_init(struct vlc_gl_interop *interop) -{ - interop->tex_count = 1; - interop->tex_target = GL_TEXTURE_2D; - interop->texs[0] = (struct vlc_gl_tex_cfg) { - { 1, 1 }, { 1, 1 }, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT - }; -} - static GLuint xyz12_shader_init(opengl_tex_converter_t *tc) { @@ -510,34 +326,6 @@ opengl_init_swizzle(const struct vlc_gl_interop *interop, return VLC_SUCCESS; } -int -opengl_interop_init_impl(struct vlc_gl_interop *interop, GLenum tex_target, - vlc_fourcc_t chroma, video_color_space_t yuv_space) -{ - bool is_yuv = vlc_fourcc_IsYUV(chroma); - const vlc_chroma_description_t *desc = - vlc_fourcc_GetChromaDescription(chroma); - if (!desc) - return VLC_EGENERIC; - - assert(!interop->fmt.p_palette); - interop->sw_fmt = interop->fmt; - interop->sw_fmt.i_chroma = chroma; - interop->sw_fmt.space = yuv_space; - interop->tex_target = tex_target; - - if (chroma == VLC_CODEC_XYZ12) - { - interop_xyz12_init(interop); - return VLC_SUCCESS; - } - - if (is_yuv) - return interop_yuv_base_init(interop, tex_target, chroma, desc); - - return interop_rgb_base_init(interop, tex_target, chroma); -} - GLuint opengl_fragment_shader_init(opengl_tex_converter_t *tc, GLenum tex_target, vlc_fourcc_t chroma, video_color_space_t yuv_space) diff --git a/modules/video_output/opengl/interop.c b/modules/video_output/opengl/interop.c new file mode 100644 index 0000000000..d65e55334c --- /dev/null +++ b/modules/video_output/opengl/interop.c @@ -0,0 +1,241 @@ +/***************************************************************************** + * interop.h + ***************************************************************************** + * Copyright (C) 2019 Videolabs + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <vlc_common.h> + +#include "interop.h" +#include "internal.h" +#include "vout_helper.h" + +static int GetTexFormatSize(const opengl_vtable_t *vt, int target, + int tex_format, int tex_internal, int tex_type) +{ + if (!vt->GetTexLevelParameteriv) + return -1; + + GLint tex_param_size; + int mul = 1; + switch (tex_format) + { + case GL_BGRA: + mul = 4; + /* fall through */ + case GL_RED: + case GL_RG: + tex_param_size = GL_TEXTURE_RED_SIZE; + break; + case GL_LUMINANCE: + tex_param_size = GL_TEXTURE_LUMINANCE_SIZE; + break; + default: + return -1; + } + GLuint texture; + + vt->GenTextures(1, &texture); + vt->BindTexture(target, texture); + vt->TexImage2D(target, 0, tex_internal, 64, 64, 0, tex_format, tex_type, NULL); + GLint size = 0; + vt->GetTexLevelParameteriv(target, 0, tex_param_size, &size); + + vt->DeleteTextures(1, &texture); + return size > 0 ? size * mul : size; +} + +static int +interop_yuv_base_init(struct vlc_gl_interop *interop, GLenum tex_target, + vlc_fourcc_t chroma, + const vlc_chroma_description_t *desc) +{ + (void) chroma; + + GLint oneplane_texfmt, oneplane16_texfmt, + twoplanes_texfmt, twoplanes16_texfmt; + + if (vlc_gl_StrHasToken(interop->glexts, "GL_ARB_texture_rg")) + { + oneplane_texfmt = GL_RED; + oneplane16_texfmt = GL_R16; + twoplanes_texfmt = GL_RG; + twoplanes16_texfmt = GL_RG16; + } + else + { + oneplane_texfmt = GL_LUMINANCE; + oneplane16_texfmt = GL_LUMINANCE16; + twoplanes_texfmt = GL_LUMINANCE_ALPHA; + twoplanes16_texfmt = 0; + } + + if (desc->pixel_size == 2) + { + if (GetTexFormatSize(interop->vt, tex_target, oneplane_texfmt, + oneplane16_texfmt, GL_UNSIGNED_SHORT) != 16) + return VLC_EGENERIC; + } + + if (desc->plane_count == 3) + { + GLint internal = 0; + GLenum type = 0; + + if (desc->pixel_size == 1) + { + internal = oneplane_texfmt; + type = GL_UNSIGNED_BYTE; + } + else if (desc->pixel_size == 2) + { + internal = oneplane16_texfmt; + type = GL_UNSIGNED_SHORT; + } + else + return VLC_EGENERIC; + + assert(internal != 0 && type != 0); + + interop->tex_count = 3; + for (unsigned i = 0; i < interop->tex_count; ++i ) + { + interop->texs[i] = (struct vlc_gl_tex_cfg) { + { desc->p[i].w.num, desc->p[i].w.den }, + { desc->p[i].h.num, desc->p[i].h.den }, + internal, oneplane_texfmt, type + }; + } + } + else if (desc->plane_count == 2) + { + interop->tex_count = 2; + + if (desc->pixel_size == 1) + { + interop->texs[0] = (struct vlc_gl_tex_cfg) { + { 1, 1 }, { 1, 1 }, oneplane_texfmt, oneplane_texfmt, + GL_UNSIGNED_BYTE + }; + interop->texs[1] = (struct vlc_gl_tex_cfg) { + { 1, 2 }, { 1, 2 }, twoplanes_texfmt, twoplanes_texfmt, + GL_UNSIGNED_BYTE + }; + } + else if (desc->pixel_size == 2) + { + if (twoplanes16_texfmt == 0 + || GetTexFormatSize(interop->vt, tex_target, twoplanes_texfmt, + twoplanes16_texfmt, GL_UNSIGNED_SHORT) != 16) + return VLC_EGENERIC; + interop->texs[0] = (struct vlc_gl_tex_cfg) { + { 1, 1 }, { 1, 1 }, oneplane16_texfmt, oneplane_texfmt, + GL_UNSIGNED_SHORT + }; + interop->texs[1] = (struct vlc_gl_tex_cfg) { + { 1, 2 }, { 1, 2 }, twoplanes16_texfmt, twoplanes_texfmt, + GL_UNSIGNED_SHORT + }; + } + else + return VLC_EGENERIC; + } + else if (desc->plane_count == 1) + { + /* Y1 U Y2 V fits in R G B A */ + interop->tex_count = 1; + interop->texs[0] = (struct vlc_gl_tex_cfg) { + { 1, 2 }, { 1, 1 }, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE + }; + } + else + return VLC_EGENERIC; + + return VLC_SUCCESS; +} + +static int +interop_rgb_base_init(struct vlc_gl_interop *interop, GLenum tex_target, + vlc_fourcc_t chroma) +{ + (void) tex_target; + + switch (chroma) + { + case VLC_CODEC_RGB32: + case VLC_CODEC_RGBA: + interop->texs[0] = (struct vlc_gl_tex_cfg) { + { 1, 1 }, { 1, 1 }, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE + }; + break; + case VLC_CODEC_BGRA: { + if (GetTexFormatSize(interop->vt, tex_target, GL_BGRA, GL_RGBA, + GL_UNSIGNED_BYTE) != 32) + return VLC_EGENERIC; + interop->texs[0] = (struct vlc_gl_tex_cfg) { + { 1, 1 }, { 1, 1 }, GL_RGBA, GL_BGRA, GL_UNSIGNED_BYTE + }; + break; + } + default: + return VLC_EGENERIC; + } + interop->tex_count = 1; + return VLC_SUCCESS; +} + +static void +interop_xyz12_init(struct vlc_gl_interop *interop) +{ + interop->tex_count = 1; + interop->tex_target = GL_TEXTURE_2D; + interop->texs[0] = (struct vlc_gl_tex_cfg) { + { 1, 1 }, { 1, 1 }, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT + }; +} + +int +opengl_interop_init_impl(struct vlc_gl_interop *interop, GLenum tex_target, + vlc_fourcc_t chroma, video_color_space_t yuv_space) +{ + bool is_yuv = vlc_fourcc_IsYUV(chroma); + const vlc_chroma_description_t *desc = + vlc_fourcc_GetChromaDescription(chroma); + if (!desc) + return VLC_EGENERIC; + + assert(!interop->fmt.p_palette); + interop->sw_fmt = interop->fmt; + interop->sw_fmt.i_chroma = chroma; + interop->sw_fmt.space = yuv_space; + interop->tex_target = tex_target; + + if (chroma == VLC_CODEC_XYZ12) + { + interop_xyz12_init(interop); + return VLC_SUCCESS; + } + + if (is_yuv) + return interop_yuv_base_init(interop, tex_target, chroma, desc); + + return interop_rgb_base_init(interop, tex_target, chroma); +} _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
