[vlc-commits] opengl: expose interop constructor and destructor

Romain Vimont git at videolan.org
Thu Feb 13 23:12:51 CET 2020


vlc | branch: master | Romain Vimont <rom1v at videolabs.io> | Tue Jan 21 11:05:22 2020 +0100| [c45f3bf6c2ab2c690849d368a3214f041f32772f] | committer: Jean-Baptiste Kempf

opengl: expose interop constructor and destructor

Expose functions to create and delete a vlc_gl_interop.

This avoids the callers to handle internal details about interop
creation and destruction.

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 modules/video_output/opengl/interop.c     | 93 +++++++++++++++++++++++++++++++
 modules/video_output/opengl/interop.h     |  8 +++
 modules/video_output/opengl/vout_helper.c | 91 +-----------------------------
 3 files changed, 103 insertions(+), 89 deletions(-)

diff --git a/modules/video_output/opengl/interop.c b/modules/video_output/opengl/interop.c
index d65e55334c..8fcdac90f2 100644
--- a/modules/video_output/opengl/interop.c
+++ b/modules/video_output/opengl/interop.c
@@ -23,11 +23,104 @@
 #endif
 
 #include <vlc_common.h>
+#include <vlc_modules.h>
 
 #include "interop.h"
 #include "internal.h"
 #include "vout_helper.h"
 
+struct vlc_gl_interop *
+vlc_gl_interop_New(struct vlc_gl_t *gl, const opengl_vtable_t *vt,
+                   vlc_video_context *context, const video_format_t *fmt,
+                   bool subpics)
+{
+    const char *glexts = (const char *) vt->GetString(GL_EXTENSIONS);
+    assert(glexts);
+    if (!glexts)
+    {
+        msg_Err(gl, "glGetString returned NULL");
+        return NULL;
+    }
+
+    struct vlc_gl_interop *interop = vlc_object_create(gl, sizeof(*interop));
+    if (!interop)
+        return NULL;
+
+#ifdef USE_OPENGL_ES2
+    interop->is_gles = true;
+#else
+    interop->is_gles = false;
+#endif
+
+    interop->init = opengl_interop_init_impl;
+    interop->ops = NULL;
+    interop->glexts = glexts;
+    interop->fmt = *fmt;
+    /* this is the only allocated field, and we don't need it */
+    interop->fmt.p_palette = NULL;
+
+    interop->gl = gl;
+    interop->vt = vt;
+
+    int ret;
+    if (subpics)
+    {
+        interop->fmt.i_chroma = VLC_CODEC_RGB32;
+        /* Normal orientation and no projection for subtitles */
+        interop->fmt.orientation = ORIENT_NORMAL;
+        interop->fmt.projection_mode = PROJECTION_MODE_RECTANGULAR;
+        interop->fmt.primaries = COLOR_PRIMARIES_UNDEF;
+        interop->fmt.transfer = TRANSFER_FUNC_UNDEF;
+        interop->fmt.space = COLOR_SPACE_UNDEF;
+
+        ret = opengl_interop_generic_init(interop, false);
+    }
+    else
+    {
+        const vlc_chroma_description_t *desc =
+            vlc_fourcc_GetChromaDescription(fmt->i_chroma);
+
+        if (desc == NULL)
+        {
+            vlc_object_delete(interop);
+            return NULL;
+        }
+        if (desc->plane_count == 0)
+        {
+            /* Opaque chroma: load a module to handle it */
+            interop->vctx = context;
+            interop->module = module_need_var(interop, "glinterop", "glinterop");
+        }
+
+        if (interop->module != NULL)
+            ret = VLC_SUCCESS;
+        else
+        {
+            /* Software chroma or gl hw converter failed: use a generic
+             * converter */
+            ret = opengl_interop_generic_init(interop, true);
+        }
+    }
+
+    if (ret != VLC_SUCCESS)
+    {
+        vlc_object_delete(interop);
+        return NULL;
+    }
+
+    return interop;
+}
+
+void
+vlc_gl_interop_Delete(struct vlc_gl_interop *interop)
+{
+    if (interop->module)
+        module_unneed(interop, interop->module);
+    if (interop->ops && interop->ops->close)
+        interop->ops->close(interop);
+    vlc_object_delete(interop);
+}
+
 static int GetTexFormatSize(const opengl_vtable_t *vt, int target,
                             int tex_format, int tex_internal, int tex_type)
 {
diff --git a/modules/video_output/opengl/interop.h b/modules/video_output/opengl/interop.h
index 530138e5c8..aea0d8e75e 100644
--- a/modules/video_output/opengl/interop.h
+++ b/modules/video_output/opengl/interop.h
@@ -156,6 +156,14 @@ struct vlc_gl_interop {
             vlc_fourcc_t chroma, video_color_space_t yuv_space);
 };
 
+struct vlc_gl_interop *
+vlc_gl_interop_New(struct vlc_gl_t *gl, const opengl_vtable_t *vt,
+                   vlc_video_context *context, const video_format_t *fmt,
+                   bool subpics);
+
+void
+vlc_gl_interop_Delete(struct vlc_gl_interop *interop);
+
 static inline int
 opengl_interop_init(struct vlc_gl_interop *interop, GLenum tex_target,
                     vlc_fourcc_t chroma, video_color_space_t yuv_space)
diff --git a/modules/video_output/opengl/vout_helper.c b/modules/video_output/opengl/vout_helper.c
index de5a355ae8..666314a28f 100644
--- a/modules/video_output/opengl/vout_helper.c
+++ b/modules/video_output/opengl/vout_helper.c
@@ -514,12 +514,7 @@ static void
 opengl_deinit_program(vout_display_opengl_t *vgl, struct prgm *prgm)
 {
     opengl_tex_converter_t *tc = prgm->tc;
-    struct vlc_gl_interop *interop = tc->interop;
-    if (interop->module != NULL)
-        module_unneed(interop, interop->module);
-    if (interop->ops && interop->ops->close)
-        interop->ops->close(interop);
-    vlc_object_delete(interop);
+    vlc_gl_interop_Delete(tc->interop);
     if (prgm->id != 0)
         vgl->vt.DeleteProgram(prgm->id);
 
@@ -532,88 +527,6 @@ opengl_deinit_program(vout_display_opengl_t *vgl, struct prgm *prgm)
     free(tc);
 }
 
-static struct vlc_gl_interop *
-CreateInterop(struct vlc_gl_t *gl, const opengl_vtable_t *vt,
-              vlc_video_context *context, const video_format_t *fmt,
-              bool subpics)
-{
-    const char *glexts = (const char *) vt->GetString(GL_EXTENSIONS);
-    assert(glexts);
-    if (!glexts)
-    {
-        msg_Err(gl, "glGetString returned NULL");
-        return NULL;
-    }
-
-    struct vlc_gl_interop *interop = vlc_object_create(gl, sizeof(*interop));
-    if (!interop)
-        return NULL;
-
-#ifdef USE_OPENGL_ES2
-    interop->is_gles = true;
-#else
-    interop->is_gles = false;
-#endif
-
-    interop->init = opengl_interop_init_impl;
-    interop->ops = NULL;
-    interop->glexts = glexts;
-    interop->fmt = *fmt;
-    /* this is the only allocated field, and we don't need it */
-    interop->fmt.p_palette = NULL;
-
-    interop->gl = gl;
-    interop->vt = vt;
-
-    int ret;
-    if (subpics)
-    {
-        interop->fmt.i_chroma = VLC_CODEC_RGB32;
-        /* Normal orientation and no projection for subtitles */
-        interop->fmt.orientation = ORIENT_NORMAL;
-        interop->fmt.projection_mode = PROJECTION_MODE_RECTANGULAR;
-        interop->fmt.primaries = COLOR_PRIMARIES_UNDEF;
-        interop->fmt.transfer = TRANSFER_FUNC_UNDEF;
-        interop->fmt.space = COLOR_SPACE_UNDEF;
-
-        ret = opengl_interop_generic_init(interop, false);
-    }
-    else
-    {
-        const vlc_chroma_description_t *desc =
-            vlc_fourcc_GetChromaDescription(fmt->i_chroma);
-
-        if (desc == NULL)
-        {
-            vlc_object_delete(interop);
-            return NULL;
-        }
-        if (desc->plane_count == 0)
-        {
-            /* Opaque chroma: load a module to handle it */
-            interop->vctx = context;
-            interop->module = module_need_var(interop, "glinterop", "glinterop");
-        }
-
-        if (interop->module != NULL)
-            ret = VLC_SUCCESS;
-        else
-        {
-            /* Software chroma or gl hw converter failed: use a generic
-             * converter */
-            ret = opengl_interop_generic_init(interop, true);
-        }
-    }
-
-    if (ret != VLC_SUCCESS)
-    {
-        vlc_object_delete(interop);
-        return NULL;
-    }
-
-    return interop;
-}
-
 static int
 opengl_init_program(vout_display_opengl_t *vgl, vlc_video_context *context,
                     struct prgm *prgm, const video_format_t *fmt, bool subpics,
@@ -624,7 +537,7 @@ opengl_init_program(vout_display_opengl_t *vgl, vlc_video_context *context,
         return VLC_ENOMEM;
 
     struct vlc_gl_interop *interop =
-        CreateInterop(vgl->gl, &vgl->vt, context, fmt, subpics);
+        vlc_gl_interop_New(vgl->gl, &vgl->vt, context, fmt, subpics);
     if (!interop)
     {
         free(tc);



More information about the vlc-commits mailing list