[vlc-devel] [PATCH 04/18] opengl: remove tex converter usages

Romain Vimont rom1v at videolabs.io
Fri Dec 20 15:48:46 CET 2019


Use importer instance directly where possible.
---
 modules/video_output/opengl/converter_sw.c    | 44 +++++++++----------
 modules/video_output/opengl/converter_vaapi.c | 12 +++--
 .../video_output/opengl/fragment_shaders.c    | 20 ++++-----
 modules/video_output/opengl/vout_helper.c     | 39 ++++++++--------
 4 files changed, 54 insertions(+), 61 deletions(-)

diff --git a/modules/video_output/opengl/converter_sw.c b/modules/video_output/opengl/converter_sw.c
index 9cea29b9bf..10c2928558 100644
--- a/modules/video_output/opengl/converter_sw.c
+++ b/modules/video_output/opengl/converter_sw.c
@@ -70,10 +70,8 @@ pbo_picture_destroy(picture_t *pic)
 }
 
 static picture_t *
-pbo_picture_create(const opengl_tex_converter_t *tc)
+pbo_picture_create(const struct vlc_gl_importer *imp)
 {
-    const struct vlc_gl_importer *imp = &tc->importer;
-
     picture_sys_t *picsys = calloc(1, sizeof(*picsys));
     if (unlikely(picsys == NULL))
         return NULL;
@@ -89,8 +87,8 @@ pbo_picture_create(const opengl_tex_converter_t *tc)
         return NULL;
     }
 
-    tc->vt->GenBuffers(pic->i_planes, picsys->buffers);
-    picsys->DeleteBuffers = tc->vt->DeleteBuffers;
+    imp->vt->GenBuffers(pic->i_planes, picsys->buffers);
+    picsys->DeleteBuffers = imp->vt->DeleteBuffers;
 
     /* XXX: needed since picture_NewFromResource override pic planes */
     if (picture_Setup(pic, &imp->fmt))
@@ -118,22 +116,22 @@ pbo_picture_create(const opengl_tex_converter_t *tc)
 }
 
 static int
-pbo_data_alloc(const opengl_tex_converter_t *tc, picture_t *pic)
+pbo_data_alloc(const struct vlc_gl_importer *imp, picture_t *pic)
 {
     picture_sys_t *picsys = pic->p_sys;
 
-    tc->vt->GetError();
+    imp->vt->GetError();
 
     for (int i = 0; i < pic->i_planes; ++i)
     {
-        tc->vt->BindBuffer(GL_PIXEL_UNPACK_BUFFER, picsys->buffers[i]);
-        tc->vt->BufferData(GL_PIXEL_UNPACK_BUFFER, picsys->bytes[i], NULL,
+        imp->vt->BindBuffer(GL_PIXEL_UNPACK_BUFFER, picsys->buffers[i]);
+        imp->vt->BufferData(GL_PIXEL_UNPACK_BUFFER, picsys->bytes[i], NULL,
                             GL_DYNAMIC_DRAW);
 
-        if (tc->vt->GetError() != GL_NO_ERROR)
+        if (imp->vt->GetError() != GL_NO_ERROR)
         {
-            msg_Err(tc->gl, "could not alloc PBO buffers");
-            tc->vt->DeleteBuffers(i, picsys->buffers);
+            msg_Err(imp->gl, "could not alloc PBO buffers");
+            imp->vt->DeleteBuffers(i, picsys->buffers);
             return VLC_EGENERIC;
         }
     }
@@ -141,21 +139,21 @@ pbo_data_alloc(const opengl_tex_converter_t *tc, picture_t *pic)
 }
 
 static int
-pbo_pics_alloc(const opengl_tex_converter_t *tc)
+pbo_pics_alloc(const struct vlc_gl_importer *imp)
 {
-    struct priv *priv = tc->importer.priv;
+    struct priv *priv = imp->priv;
     for (size_t i = 0; i < PBO_DISPLAY_COUNT; ++i)
     {
-        picture_t *pic = priv->pbo.display_pics[i] = pbo_picture_create(tc);
+        picture_t *pic = priv->pbo.display_pics[i] = pbo_picture_create(imp);
         if (pic == NULL)
             goto error;
 
-        if (pbo_data_alloc(tc, pic) != VLC_SUCCESS)
+        if (pbo_data_alloc(imp, pic) != VLC_SUCCESS)
             goto error;
     }
 
     /* turn off pbo */
-    tc->vt->BindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
+    imp->vt->BindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
 
     return VLC_SUCCESS;
 error:
@@ -308,7 +306,7 @@ opengl_tex_converter_generic_init(opengl_tex_converter_t *tc, bool allow_dr)
     if (vlc_fourcc_IsYUV(imp->fmt.i_chroma))
     {
         GLint max_texture_units = 0;
-        tc->vt->GetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &max_texture_units);
+        imp->vt->GetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &max_texture_units);
         if (max_texture_units < 3)
             return VLC_EGENERIC;
 
@@ -358,7 +356,7 @@ opengl_tex_converter_generic_init(opengl_tex_converter_t *tc, bool allow_dr)
     struct priv *priv = imp->priv = calloc(1, sizeof(struct priv));
     if (unlikely(priv == NULL))
     {
-        tc->vt->DeleteShader(fragment_shader);
+        imp->vt->DeleteShader(fragment_shader);
         return VLC_ENOMEM;
     }
 
@@ -375,16 +373,16 @@ opengl_tex_converter_generic_init(opengl_tex_converter_t *tc, bool allow_dr)
     if (allow_dr && priv->has_unpack_subimage)
     {
         /* Ensure we do direct rendering / PBO with OpenGL 3.0 or higher. */
-        const unsigned char *ogl_version = tc->vt->GetString(GL_VERSION);
+        const unsigned char *ogl_version = imp->vt->GetString(GL_VERSION);
         const bool glver_ok = strverscmp((const char *)ogl_version, "3.0") >= 0;
 
         const bool has_pbo = glver_ok &&
             (vlc_gl_StrHasToken(imp->glexts, "GL_ARB_pixel_buffer_object") ||
              vlc_gl_StrHasToken(imp->glexts, "GL_EXT_pixel_buffer_object"));
 
-        const bool supports_pbo = has_pbo && tc->vt->BufferData
-            && tc->vt->BufferSubData;
-        if (supports_pbo && pbo_pics_alloc(tc) == VLC_SUCCESS)
+        const bool supports_pbo = has_pbo && imp->vt->BufferData
+            && imp->vt->BufferSubData;
+        if (supports_pbo && pbo_pics_alloc(imp) == VLC_SUCCESS)
         {
             static const struct vlc_gl_importer_ops pbo_ops = {
                 .allocate_textures = tc_common_allocate_textures,
diff --git a/modules/video_output/opengl/converter_vaapi.c b/modules/video_output/opengl/converter_vaapi.c
index 177b9cda41..5ff3c7f24e 100644
--- a/modules/video_output/opengl/converter_vaapi.c
+++ b/modules/video_output/opengl/converter_vaapi.c
@@ -101,10 +101,8 @@ vaegl_release_last_pic(const struct vlc_gl_importer *imp, struct priv *priv)
 }
 
 static int
-vaegl_init_fourcc(const opengl_tex_converter_t *tc, struct priv *priv,
-                  unsigned va_fourcc)
+vaegl_init_fourcc(struct priv *priv, unsigned va_fourcc)
 {
-    (void) tc;
     switch (va_fourcc)
     {
         case VA_FOURCC_NV12:
@@ -305,7 +303,7 @@ static int strcasecmp_void(const void *a, const void *b)
 }
 
 static int
-tc_va_check_interop_blacklist(opengl_tex_converter_t *tc, VADisplay *vadpy)
+tc_va_check_interop_blacklist(const struct vlc_gl_importer *imp, VADisplay *vadpy)
 {
     const char *vendor = vaQueryVendorString(vadpy);
     if (vendor == NULL)
@@ -326,7 +324,7 @@ tc_va_check_interop_blacklist(opengl_tex_converter_t *tc, VADisplay *vadpy)
                                 BL_SIZE_MAX, strcasecmp_void);
     if (found != NULL)
     {
-        msg_Warn(tc->gl, "The '%s' driver is blacklisted: no interop", found);
+        msg_Warn(imp->gl, "The '%s' driver is blacklisted: no interop", found);
         return VLC_EGENERIC;
     }
 
@@ -407,7 +405,7 @@ Open(vlc_object_t *obj)
             vlc_assert_unreachable();
     }
 
-    if (vaegl_init_fourcc(tc, priv, va_fourcc))
+    if (vaegl_init_fourcc(priv, va_fourcc))
         goto error;
 
     priv->glEGLImageTargetTexture2DOES =
@@ -418,7 +416,7 @@ Open(vlc_object_t *obj)
     priv->vadpy = dec_device->opaque;
     assert(priv->vadpy != NULL);
 
-    if (tc_va_check_interop_blacklist(tc, priv->vadpy))
+    if (tc_va_check_interop_blacklist(imp, priv->vadpy))
         goto error;
 
     if (tc_va_check_derive_image(imp))
diff --git a/modules/video_output/opengl/fragment_shaders.c b/modules/video_output/opengl/fragment_shaders.c
index 6b6ce7f01e..5f5b8326fd 100644
--- a/modules/video_output/opengl/fragment_shaders.c
+++ b/modules/video_output/opengl/fragment_shaders.c
@@ -62,10 +62,10 @@
 # define GL_TEXTURE_LUMINANCE_SIZE 0x8060
 #endif
 
-static int GetTexFormatSize(opengl_tex_converter_t *tc, int target,
+static int GetTexFormatSize(const opengl_vtable_t *vt, int target,
                             int tex_format, int tex_internal, int tex_type)
 {
-    if (!tc->vt->GetTexLevelParameteriv)
+    if (!vt->GetTexLevelParameteriv)
         return -1;
 
     GLint tex_param_size;
@@ -87,13 +87,13 @@ static int GetTexFormatSize(opengl_tex_converter_t *tc, int target,
     }
     GLuint texture;
 
-    tc->vt->GenTextures(1, &texture);
-    tc->vt->BindTexture(target, texture);
-    tc->vt->TexImage2D(target, 0, tex_internal, 64, 64, 0, tex_format, tex_type, NULL);
+    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;
-    tc->vt->GetTexLevelParameteriv(target, 0, tex_param_size, &size);
+    vt->GetTexLevelParameteriv(target, 0, tex_param_size, &size);
 
-    tc->vt->DeleteTextures(1, &texture);
+    vt->DeleteTextures(1, &texture);
     return size > 0 ? size * mul : size;
 }
 
@@ -126,7 +126,7 @@ tc_yuv_base_init(opengl_tex_converter_t *tc, GLenum tex_target,
     float yuv_range_correction = 1.0;
     if (desc->pixel_size == 2)
     {
-        if (GetTexFormatSize(tc, tex_target, oneplane_texfmt,
+        if (GetTexFormatSize(tc->vt, tex_target, oneplane_texfmt,
                              oneplane16_texfmt, GL_UNSIGNED_SHORT) != 16)
             return VLC_EGENERIC;
 
@@ -187,7 +187,7 @@ tc_yuv_base_init(opengl_tex_converter_t *tc, GLenum tex_target,
         else if (desc->pixel_size == 2)
         {
             if (twoplanes16_texfmt == 0
-             || GetTexFormatSize(tc, tex_target, twoplanes_texfmt,
+             || GetTexFormatSize(tc->vt, tex_target, twoplanes_texfmt,
                                  twoplanes16_texfmt, GL_UNSIGNED_SHORT) != 16)
                 return VLC_EGENERIC;
             imp->texs[0] = (struct vlc_gl_tex_cfg) {
@@ -316,7 +316,7 @@ tc_rgb_base_init(opengl_tex_converter_t *tc, GLenum tex_target,
             };
             break;
         case VLC_CODEC_BGRA: {
-            if (GetTexFormatSize(tc, tex_target, GL_BGRA, GL_RGBA,
+            if (GetTexFormatSize(tc->vt, tex_target, GL_BGRA, GL_RGBA,
                                  GL_UNSIGNED_BYTE) != 32)
                 return VLC_EGENERIC;
             imp->texs[0] = (struct vlc_gl_tex_cfg) {
diff --git a/modules/video_output/opengl/vout_helper.c b/modules/video_output/opengl/vout_helper.c
index 8b07577a41..06e58bd239 100644
--- a/modules/video_output/opengl/vout_helper.c
+++ b/modules/video_output/opengl/vout_helper.c
@@ -353,36 +353,34 @@ static GLuint BuildVertexShader(const opengl_tex_converter_t *tc,
 }
 
 static int
-GenTextures(const opengl_tex_converter_t *tc,
+GenTextures(const struct vlc_gl_importer *imp,
             const GLsizei *tex_width, const GLsizei *tex_height,
             GLuint *textures)
 {
-    const struct vlc_gl_importer *imp = &tc->importer;
-
-    tc->vt->GenTextures(imp->tex_count, textures);
+    imp->vt->GenTextures(imp->tex_count, textures);
 
     for (unsigned i = 0; i < imp->tex_count; i++)
     {
-        tc->vt->BindTexture(imp->tex_target, textures[i]);
+        imp->vt->BindTexture(imp->tex_target, textures[i]);
 
 #if !defined(USE_OPENGL_ES2)
         /* Set the texture parameters */
-        tc->vt->TexParameterf(imp->tex_target, GL_TEXTURE_PRIORITY, 1.0);
-        tc->vt->TexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+        imp->vt->TexParameterf(imp->tex_target, GL_TEXTURE_PRIORITY, 1.0);
+        imp->vt->TexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 #endif
 
-        tc->vt->TexParameteri(imp->tex_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-        tc->vt->TexParameteri(imp->tex_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-        tc->vt->TexParameteri(imp->tex_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-        tc->vt->TexParameteri(imp->tex_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+        imp->vt->TexParameteri(imp->tex_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+        imp->vt->TexParameteri(imp->tex_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+        imp->vt->TexParameteri(imp->tex_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+        imp->vt->TexParameteri(imp->tex_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
     }
 
     if (imp->ops->allocate_textures != NULL)
     {
-        int ret = imp->ops->allocate_textures(&tc->importer, textures, tex_width, tex_height);
+        int ret = imp->ops->allocate_textures(imp, textures, tex_width, tex_height);
         if (ret != VLC_SUCCESS)
         {
-            tc->vt->DeleteTextures(imp->tex_count, textures);
+            imp->vt->DeleteTextures(imp->tex_count, textures);
             memset(textures, 0, imp->tex_count * sizeof(GLuint));
             return ret;
         }
@@ -391,10 +389,9 @@ GenTextures(const opengl_tex_converter_t *tc,
 }
 
 static void
-DelTextures(const opengl_tex_converter_t *tc, GLuint *textures)
+DelTextures(const struct vlc_gl_importer *imp, GLuint *textures)
 {
-    const struct vlc_gl_importer *imp = &tc->importer;
-    tc->vt->DeleteTextures(imp->tex_count, textures);
+    imp->vt->DeleteTextures(imp->tex_count, textures);
     memset(textures, 0, imp->tex_count * sizeof(GLuint));
 }
 
@@ -881,7 +878,7 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
 
     if (!imp->handle_texs_gen)
     {
-        ret = GenTextures(vgl->prgm->tc, vgl->tex_width, vgl->tex_height,
+        ret = GenTextures(&vgl->prgm->tc->importer, vgl->tex_width, vgl->tex_height,
                           vgl->texture);
         if (ret != VLC_SUCCESS)
         {
@@ -1071,7 +1068,7 @@ picture_pool_t *vout_display_opengl_GetPool(vout_display_opengl_t *vgl, unsigned
     return vgl->pool;
 
 error:
-    DelTextures(tc, vgl->texture);
+    DelTextures(imp, vgl->texture);
     return NULL;
 }
 
@@ -1081,7 +1078,7 @@ int vout_display_opengl_Prepare(vout_display_opengl_t *vgl,
     GL_ASSERT_NOERROR();
 
     opengl_tex_converter_t *tc = vgl->prgm->tc;
-    struct vlc_gl_importer *imp = &tc->importer;
+    const struct vlc_gl_importer *imp = &tc->importer;
 
     /* Update the texture */
     int ret = imp->ops->update_textures(imp, vgl->texture, vgl->tex_width, vgl->tex_height,
@@ -1147,7 +1144,7 @@ int vout_display_opengl_Prepare(vout_display_opengl_t *vgl,
             if (!glr->texture)
             {
                 /* Could not recycle a previous texture, generate a new one. */
-                ret = GenTextures(tc, &glr->width, &glr->height, &glr->texture);
+                ret = GenTextures(imp, &glr->width, &glr->height, &glr->texture);
                 if (ret != VLC_SUCCESS)
                     continue;
             }
@@ -1161,7 +1158,7 @@ int vout_display_opengl_Prepare(vout_display_opengl_t *vgl,
     }
     for (int i = 0; i < last_count; i++) {
         if (last[i].texture)
-            DelTextures(tc, &last[i].texture);
+            DelTextures(imp, &last[i].texture);
     }
     free(last);
 
-- 
2.24.1



More information about the vlc-devel mailing list