[vlc-commits] opengl: converter: replace chroma desc

Thomas Guillem git at videolan.org
Thu Feb 2 09:52:49 CET 2017


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed Feb  1 11:32:16 2017 +0100| [121ed409711a62d99e6487dc44ef67600f31a1bf] | committer: Thomas Guillem

opengl: converter: replace chroma desc

Replace it with a tex_count and a list of w/h scale factor.
vlc_chroma_description_t is not enough to specify how textures should be
scaled. For example, opaque formats don't have any planes, or UV planes can
be splitted (for NV12).

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=121ed409711a62d99e6487dc44ef67600f31a1bf
---

 modules/video_output/opengl/converter_android.c | 13 +-----
 modules/video_output/opengl/converters.c        | 29 ++++++-------
 modules/video_output/opengl/internal.h          | 14 +++++-
 modules/video_output/opengl/vout_helper.c       | 58 ++++++++++++-------------
 4 files changed, 56 insertions(+), 58 deletions(-)

diff --git a/modules/video_output/opengl/converter_android.c b/modules/video_output/opengl/converter_android.c
index 4abe40a..d6f0964 100644
--- a/modules/video_output/opengl/converter_android.c
+++ b/modules/video_output/opengl/converter_android.c
@@ -204,19 +204,10 @@ opengl_tex_converter_anop_init(const video_format_t *fmt,
     tc->pf_prepare_shader = tc_anop_prepare_shader;
     tc->pf_release        = tc_anop_release;
 
-    /* fake plane_count to 1 */
-    static const vlc_chroma_description_t desc = {
-        .plane_count = 1,
-        .p[0].w.num = 1,
-        .p[0].w.den = 1,
-        .p[0].h.num = 1,
-        .p[0].h.den = 1,
-        .pixel_size = 0,
-        .pixel_bits = 0,
-    };
+    tc->tex_count = 1;
+    tc->texs[0] = (struct opengl_tex_cfg) { { 1, 1 }, { 1, 1 } };
 
     tc->chroma       = VLC_CODEC_ANDROID_OPAQUE;
-    tc->desc         = &desc;
     tc->tex_target   = GL_TEXTURE_EXTERNAL_OES;
 
     /* The transform Matrix (uSTMatrix) given by the SurfaceTexture is not
diff --git a/modules/video_output/opengl/converters.c b/modules/video_output/opengl/converters.c
index 6ad3661..9ddf088 100644
--- a/modules/video_output/opengl/converters.c
+++ b/modules/video_output/opengl/converters.c
@@ -148,9 +148,12 @@ tc_yuv_base_init(opengl_tex_converter_t *tc, GLenum tex_target,
 
         assert(internal != 0);
 
-        for (unsigned i = 0; i < desc->plane_count; ++i )
+        tc->tex_count = 3;
+        for (unsigned i = 0; i < tc->tex_count; ++i )
         {
             tc->texs[i] = (struct opengl_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, GL_UNSIGNED_BYTE
             };
         }
@@ -197,7 +200,6 @@ tc_yuv_base_init(opengl_tex_converter_t *tc, GLenum tex_target,
 
     tc->chroma = chroma;
     tc->yuv_color = true;
-    tc->desc = desc;
 
     *swap_uv = chroma == VLC_CODEC_YV12 || chroma == VLC_CODEC_YV9;
     return VLC_SUCCESS;
@@ -213,11 +215,9 @@ tc_rgba_base_init(opengl_tex_converter_t *tc, GLenum tex_target,
         return VLC_EGENERIC;
 
     tc->chroma = VLC_CODEC_RGBA;
-    tc->desc = vlc_fourcc_GetChromaDescription(chroma);
-    assert(tc->desc != NULL);
-
+    tc->tex_count = 1;
     tc->texs[0] = (struct opengl_tex_cfg) {
-        GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE
+        { 1, 1 }, { 1, 1 }, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE
     };
     return VLC_SUCCESS;
 }
@@ -233,7 +233,7 @@ tc_base_fetch_locations(opengl_tex_converter_t *tc, GLuint program)
             return VLC_EGENERIC;
     }
 
-    for (unsigned int i = 0; i < tc->desc->plane_count; ++i)
+    for (unsigned int i = 0; i < tc->tex_count; ++i)
     {
         char name[sizeof("TextureX")];
         snprintf(name, sizeof(name), "Texture%1u", i);
@@ -258,7 +258,7 @@ tc_base_prepare_shader(const opengl_tex_converter_t *tc,
     if (tc->yuv_color)
         tc->api->Uniform4fv(tc->uloc.Coefficients, 4, tc->yuv_coefficients);
 
-    for (unsigned i = 0; i < tc->desc->plane_count; ++i)
+    for (unsigned i = 0; i < tc->tex_count; ++i)
         tc->api->Uniform1i(tc->uloc.Texture[i], i);
 
     tc->api->Uniform4f(tc->uloc.FillColor, 1.0f, 1.0f, 1.0f, alpha);
@@ -302,7 +302,7 @@ opengl_fragment_shader_init(opengl_tex_converter_t *tc, GLenum tex_target,
 
     ADD("#version " GLSL_VERSION "\n" PRECISION);
 
-    for (unsigned i = 0; i < tc->desc->plane_count; ++i)
+    for (unsigned i = 0; i < tc->tex_count; ++i)
         ADDF("uniform %s Texture%u;"
              "varying vec2 TexCoord%u;", sampler, i, i);
 
@@ -314,7 +314,7 @@ opengl_fragment_shader_init(opengl_tex_converter_t *tc, GLenum tex_target,
         "float val;vec4 colors;");
 
     unsigned color_idx = 0;
-    for (unsigned i = 0; i < tc->desc->plane_count; ++i)
+    for (unsigned i = 0; i < tc->tex_count; ++i)
     {
         const char *swizzle = swizzle_per_tex[i];
         if (swizzle)
@@ -582,7 +582,7 @@ tc_common_get_pool(const opengl_tex_converter_t *tc, const video_format_t *fmt,
         }
 
         assert(pic->i_planes > 0
-            && (unsigned) pic->i_planes == tc->desc->plane_count);
+            && (unsigned) pic->i_planes == tc->tex_count);
 
         for (int i = 0; i < pic->i_planes; ++i)
         {
@@ -707,7 +707,7 @@ tc_common_update(const opengl_tex_converter_t *tc, GLuint *textures,
 #endif
 
     int ret = VLC_SUCCESS;
-    for (unsigned i = 0; i < tc->desc->plane_count && ret == VLC_SUCCESS; i++)
+    for (unsigned i = 0; i < tc->tex_count && ret == VLC_SUCCESS; i++)
     {
         assert(textures[i] != 0);
         glActiveTexture(GL_TEXTURE0 + i);
@@ -835,11 +835,10 @@ opengl_tex_converter_xyz12_init(const video_format_t *fmt,
         return 0;
 
     tc->chroma  = VLC_CODEC_XYZ12;
-    tc->desc    = vlc_fourcc_GetChromaDescription(tc->chroma);
-    assert(tc->desc != NULL);
+    tc->tex_count = 1;
     tc->tex_target = GL_TEXTURE_2D;
     tc->texs[0] = (struct opengl_tex_cfg) {
-        GL_RGB, GL_RGB, GL_UNSIGNED_SHORT
+        { 1, 1 }, { 1, 1 }, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT
     };
 
     tc->pf_fetch_locations = tc_xyz12_fetch_locations;
diff --git a/modules/video_output/opengl/internal.h b/modules/video_output/opengl/internal.h
index ef56324..142c8e8 100644
--- a/modules/video_output/opengl/internal.h
+++ b/modules/video_output/opengl/internal.h
@@ -168,13 +168,23 @@ struct opengl_tex_converter_t
     /* Video chroma used by this configuration, cannot be 0 */
     vlc_fourcc_t chroma;
 
-    /* Description of the chroma, cannot be NULL */
-    const vlc_chroma_description_t *desc;
+    /* Number of textures, cannot be 0 */
+    unsigned tex_count;
 
     /* Texture mapping (usually: GL_TEXTURE_2D), cannot be 0 */
     GLenum tex_target;
 
     struct opengl_tex_cfg {
+        /* Texture scale factor, cannot be 0 */
+        struct {
+            unsigned num;
+            unsigned den;
+        } w;
+        struct {
+            unsigned num;
+            unsigned den;
+        } h;
+
         /* The following is used and filled by the opengl_fragment_shader_init
          * function. */
         GLint  internal;
diff --git a/modules/video_output/opengl/vout_helper.c b/modules/video_output/opengl/vout_helper.c
index e3b3ae5..07f1964 100644
--- a/modules/video_output/opengl/vout_helper.c
+++ b/modules/video_output/opengl/vout_helper.c
@@ -107,7 +107,6 @@ struct vout_display_opengl_t {
     opengl_shaders_api_t api;
 
     video_format_t fmt;
-    const vlc_chroma_description_t *chroma;
 
     GLsizei    tex_width[PICTURE_PLANE_MAX];
     GLsizei    tex_height[PICTURE_PLANE_MAX];
@@ -389,9 +388,9 @@ GenTextures(const opengl_tex_converter_t *tc,
             const GLsizei *tex_width, const GLsizei *tex_height,
             GLuint *textures)
 {
-    glGenTextures(tc->desc->plane_count, textures);
+    glGenTextures(tc->tex_count, textures);
 
-    for (unsigned i = 0; i < tc->desc->plane_count; i++)
+    for (unsigned i = 0; i < tc->tex_count; i++)
     {
         glActiveTexture(GL_TEXTURE0 + i);
         glClientActiveTexture(GL_TEXTURE0 + i);
@@ -416,7 +415,7 @@ GenTextures(const opengl_tex_converter_t *tc,
                 if (i > 0)
                 {
                     glDeleteTextures(i, textures);
-                    memset(textures, 0, tc->desc->plane_count * sizeof(GLuint));
+                    memset(textures, 0, tc->tex_count * sizeof(GLuint));
                 }
                 return ret;
             }
@@ -428,8 +427,8 @@ GenTextures(const opengl_tex_converter_t *tc,
 static void
 DelTextures(const opengl_tex_converter_t *tc, GLuint *textures)
 {
-    glDeleteTextures(tc->desc->plane_count, textures);
-    memset(textures, 0, tc->desc->plane_count * sizeof(GLuint));
+    glDeleteTextures(tc->tex_count, textures);
+    memset(textures, 0, tc->tex_count * sizeof(GLuint));
 }
 
 vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
@@ -578,7 +577,7 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
             if (fragment_shader != 0)
             {
                 assert(tex_conv.chroma != 0 && tex_conv.tex_target != 0 &&
-                       tex_conv.pf_update != NULL &&
+                       tex_conv.tex_count > 0 &&  tex_conv.pf_update != NULL &&
                        tex_conv.pf_fetch_locations != NULL &&
                        tex_conv.pf_prepare_shader != NULL);
                 vgl->fmt = *fmt;
@@ -599,8 +598,8 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
 
     /* Build program if needed */
     GLuint vertex_shader, sub_vertex_shader;
-    vertex_shader = BuildVertexShader(vgl, tex_conv.desc->plane_count);
-    sub_vertex_shader = BuildVertexShader(vgl, sub_tex_conv.desc->plane_count);
+    vertex_shader = BuildVertexShader(vgl, tex_conv.tex_count);
+    sub_vertex_shader = BuildVertexShader(vgl, sub_tex_conv.tex_count);
 
     const GLuint shaders[] = {
         fragment_shader,
@@ -674,9 +673,6 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
         }
     }
 
-    vgl->chroma = vgl->prgm->tc.desc;
-    assert(vgl->chroma != NULL);
-
     /* Fetch UniformLocations and AttribLocations */
     for (GLuint i = 0; i < 2; i++)
     {
@@ -702,11 +698,11 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
         GET_ALOC(VertexPosition, "VertexPosition");
         GET_ALOC(MultiTexCoord[0], "MultiTexCoord0");
         /* MultiTexCoord 1 and 2 can be optimized out if not used */
-        if (prgm->tc.desc->plane_count > 1)
+        if (prgm->tc.tex_count > 1)
             GET_ALOC(MultiTexCoord[1], "MultiTexCoord1");
         else
             prgm->aloc.MultiTexCoord[1] = -1;
-        if (prgm->tc.desc->plane_count > 2)
+        if (prgm->tc.tex_count > 2)
             GET_ALOC(MultiTexCoord[2], "MultiTexCoord2");
         else
             prgm->aloc.MultiTexCoord[2] = -1;
@@ -733,11 +729,12 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
     getViewpointMatrixes(vgl, PROJECTION_MODE_RECTANGULAR, vgl->sub_prgm);
 
     /* Texture size */
-    for (unsigned j = 0; j < vgl->chroma->plane_count; j++) {
-        const GLsizei w = vgl->fmt.i_visible_width  * vgl->chroma->p[j].w.num
-                        / vgl->chroma->p[j].w.den;
-        const GLsizei h = vgl->fmt.i_visible_height * vgl->chroma->p[j].h.num
-                        / vgl->chroma->p[j].h.den;
+    const opengl_tex_converter_t *tc = &vgl->prgm->tc;
+    for (unsigned j = 0; j < tc->tex_count; j++) {
+        const GLsizei w = vgl->fmt.i_visible_width  * tc->texs[j].w.num
+                        / tc->texs[j].w.den;
+        const GLsizei h = vgl->fmt.i_visible_height * tc->texs[j].h.num
+                        / tc->texs[j].h.den;
         if (vgl->supports_npot) {
             vgl->tex_width[j]  = w;
             vgl->tex_height[j] = h;
@@ -757,7 +754,7 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
 
     vgl->api.GenBuffers(1, &vgl->vertex_buffer_object);
     vgl->api.GenBuffers(1, &vgl->index_buffer_object);
-    vgl->api.GenBuffers(vgl->chroma->plane_count, vgl->texture_buffer_object);
+    vgl->api.GenBuffers(vgl->prgm->tc.tex_count, vgl->texture_buffer_object);
 
     /* Initial number of allocated buffer objects for subpictures, will grow dynamically. */
     int subpicture_buffer_object_count = 8;
@@ -816,8 +813,8 @@ void vout_display_opengl_Delete(vout_display_opengl_t *vgl)
     }
     vgl->api.DeleteBuffers(1, &vgl->vertex_buffer_object);
     vgl->api.DeleteBuffers(1, &vgl->index_buffer_object);
-    if (vgl->chroma != NULL)
-        vgl->api.DeleteBuffers(vgl->chroma->plane_count, vgl->texture_buffer_object);
+
+    vgl->api.DeleteBuffers(vgl->prgm->tc.tex_count, vgl->texture_buffer_object);
     if (vgl->subpicture_buffer_object_count > 0)
         vgl->api.DeleteBuffers(vgl->subpicture_buffer_object_count, vgl->subpicture_buffer_object);
     free(vgl->subpicture_buffer_object);
@@ -1312,19 +1309,19 @@ static int SetupCoords(vout_display_opengl_t *vgl,
     switch (vgl->fmt.projection_mode)
     {
     case PROJECTION_MODE_RECTANGULAR:
-        i_ret = BuildRectangle(vgl->chroma->plane_count,
+        i_ret = BuildRectangle(vgl->prgm->tc.tex_count,
                                &vertexCoord, &textureCoord, &nbVertices,
                                &indices, &nbIndices,
                                left, top, right, bottom);
         break;
     case PROJECTION_MODE_EQUIRECTANGULAR:
-        i_ret = BuildSphere(vgl->chroma->plane_count,
+        i_ret = BuildSphere(vgl->prgm->tc.tex_count,
                             &vertexCoord, &textureCoord, &nbVertices,
                             &indices, &nbIndices,
                             left, top, right, bottom);
         break;
     case PROJECTION_MODE_CUBEMAP_LAYOUT_STANDARD:
-        i_ret = BuildCube(vgl->chroma->plane_count,
+        i_ret = BuildCube(vgl->prgm->tc.tex_count,
                           (float)vgl->fmt.i_cubemap_padding / vgl->fmt.i_width,
                           (float)vgl->fmt.i_cubemap_padding / vgl->fmt.i_height,
                           &vertexCoord, &textureCoord, &nbVertices,
@@ -1339,7 +1336,7 @@ static int SetupCoords(vout_display_opengl_t *vgl,
     if (i_ret != VLC_SUCCESS)
         return i_ret;
 
-    for (unsigned j = 0; j < vgl->chroma->plane_count; j++)
+    for (unsigned j = 0; j < vgl->prgm->tc.tex_count; j++)
     {
         vgl->api.BindBuffer(GL_ARRAY_BUFFER, vgl->texture_buffer_object[j]);
         vgl->api.BufferData(GL_ARRAY_BUFFER, nbVertices * 2 * sizeof(GLfloat),
@@ -1368,7 +1365,7 @@ static void DrawWithShaders(vout_display_opengl_t *vgl, struct prgm *prgm)
     opengl_tex_converter_t *tc = &prgm->tc;
     tc->pf_prepare_shader(tc, vgl->tex_width, vgl->tex_height, 1.0f);
 
-    for (unsigned j = 0; j < vgl->chroma->plane_count; j++) {
+    for (unsigned j = 0; j < vgl->prgm->tc.tex_count; j++) {
         assert(vgl->texture[j] != 0);
         glActiveTexture(GL_TEXTURE0+j);
         glClientActiveTexture(GL_TEXTURE0+j);
@@ -1422,11 +1419,12 @@ int vout_display_opengl_Display(vout_display_opengl_t *vgl,
         float top[PICTURE_PLANE_MAX];
         float right[PICTURE_PLANE_MAX];
         float bottom[PICTURE_PLANE_MAX];
-        for (unsigned j = 0; j < vgl->chroma->plane_count; j++)
+        const opengl_tex_converter_t *tc = &vgl->prgm->tc;
+        for (unsigned j = 0; j < tc->tex_count; j++)
         {
-            float scale_w = (float)vgl->chroma->p[j].w.num / vgl->chroma->p[j].w.den
+            float scale_w = (float)tc->texs[j].w.num / tc->texs[j].w.den
                           / vgl->tex_width[j];
-            float scale_h = (float)vgl->chroma->p[j].h.num / vgl->chroma->p[j].h.den
+            float scale_h = (float)tc->texs[j].h.num / tc->texs[j].h.den
                           / vgl->tex_height[j];
 
             /* Warning: if NPOT is not supported a larger texture is



More information about the vlc-commits mailing list