[vlc-devel] [PATCH 17/41] opengl: move interop ownership to vgl

Romain Vimont rom1v at videolabs.io
Fri Feb 7 17:42:03 CET 2020


The interop instances were owned by the renderers.

To prepare for making the renderers independant of the input picture
(in particular, independant of the interop), make the vgl own the
interop instances.
---
 modules/video_output/opengl/renderer.c     | 15 ++--------
 modules/video_output/opengl/renderer.h     |  4 +--
 modules/video_output/opengl/sub_renderer.c | 21 ++++++--------
 modules/video_output/opengl/sub_renderer.h |  4 ++-
 modules/video_output/opengl/vout_helper.c  | 32 ++++++++++++++++++++--
 5 files changed, 45 insertions(+), 31 deletions(-)

diff --git a/modules/video_output/opengl/renderer.c b/modules/video_output/opengl/renderer.c
index 593f6e0437..7b1cca6a1d 100644
--- a/modules/video_output/opengl/renderer.c
+++ b/modules/video_output/opengl/renderer.c
@@ -415,7 +415,6 @@ vlc_gl_renderer_Delete(struct vlc_gl_renderer *renderer)
     if (!interop->handle_texs_gen)
         vt->DeleteTextures(interop->tex_count, sampler->textures);
 
-    vlc_gl_interop_Delete(interop);
     if (renderer->program_id != 0)
         vt->DeleteProgram(renderer->program_id);
 
@@ -433,8 +432,8 @@ static int SetupCoords(struct vlc_gl_renderer *renderer);
 
 struct vlc_gl_renderer *
 vlc_gl_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
-                    vlc_video_context *context, const video_format_t *fmt,
-                    bool b_dump_shaders)
+                    struct vlc_gl_interop *interop,
+                    const video_format_t *fmt, bool b_dump_shaders)
 {
     const opengl_vtable_t *vt = &api->vt;
 
@@ -450,16 +449,6 @@ vlc_gl_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
     }
 
     renderer->sampler = sampler;
-
-    struct vlc_gl_interop *interop =
-        vlc_gl_interop_New(gl, api, context, fmt, false);
-    if (!interop)
-    {
-        free(renderer);
-        free(sampler);
-        return NULL;
-    }
-
     renderer->interop = interop;
 
     renderer->gl = gl;
diff --git a/modules/video_output/opengl/renderer.h b/modules/video_output/opengl/renderer.h
index 0f6e3dcef8..9c426ccbaf 100644
--- a/modules/video_output/opengl/renderer.h
+++ b/modules/video_output/opengl/renderer.h
@@ -130,13 +130,13 @@ struct vlc_gl_renderer
  *
  * \param gl the GL context
  * \param api the OpenGL API
- * \param context the video context
+ * \param interop the interop
  * \param fmt the video format
  * \param dump_shaders indicate if the shaders must be dumped in logs
  */
 struct vlc_gl_renderer *
 vlc_gl_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
-                    vlc_video_context *context, const video_format_t *fmt,
+                    struct vlc_gl_interop *interop, const video_format_t *fmt,
                     bool dump_shaders);
 
 /**
diff --git a/modules/video_output/opengl/sub_renderer.c b/modules/video_output/opengl/sub_renderer.c
index a06a9826ae..a9cb2cf359 100644
--- a/modules/video_output/opengl/sub_renderer.c
+++ b/modules/video_output/opengl/sub_renderer.c
@@ -112,7 +112,8 @@ FetchLocations(struct vlc_gl_sub_renderer *sr)
 }
 
 struct vlc_gl_sub_renderer *
-vlc_gl_sub_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api)
+vlc_gl_sub_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
+                        struct vlc_gl_interop *interop)
 {
     const opengl_vtable_t *vt = &api->vt;
 
@@ -122,13 +123,11 @@ vlc_gl_sub_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api)
 
     video_format_t fmt;
     video_format_Init(&fmt, VLC_CODEC_RGB32);
-    sr->interop = vlc_gl_interop_New(gl, api, NULL, &fmt, true);
-    if (!sr->interop)
-        goto error_1;
 
     /* Allocates our textures */
-    assert(!sr->interop->handle_texs_gen);
+    assert(!interop->handle_texs_gen);
 
+    sr->interop = interop;
     sr->gl = gl;
     sr->api = api;
     sr->vt = vt;
@@ -162,17 +161,17 @@ vlc_gl_sub_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api)
                             1, (const char **) &VERTEX_SHADER_SRC,
                             1, (const char **) &FRAGMENT_SHADER_SRC);
     if (!sr->program_id)
-        goto error_2;
+        goto error_1;
 
     int ret = FetchLocations(sr);
     if (ret != VLC_SUCCESS)
-        goto error_3;
+        goto error_2;
 
     /* Initial number of allocated buffer objects for subpictures, will grow dynamically. */
     static const unsigned INITIAL_BUFFER_OBJECT_COUNT = 8;
     sr->buffer_objects = vlc_alloc(INITIAL_BUFFER_OBJECT_COUNT, sizeof(GLuint));
     if (!sr->buffer_objects)
-        goto error_3;
+        goto error_2;
 
     sr->buffer_object_count = INITIAL_BUFFER_OBJECT_COUNT;
 
@@ -180,10 +179,8 @@ vlc_gl_sub_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api)
 
     return sr;
 
-error_3:
-    vt->DeleteProgram(sr->program_id);
 error_2:
-    vlc_object_delete(sr->interop);
+    vt->DeleteProgram(sr->program_id);
 error_1:
     free(sr);
 
@@ -204,8 +201,6 @@ vlc_gl_sub_renderer_Delete(struct vlc_gl_sub_renderer *sr)
     }
     free(sr->regions);
 
-    vlc_gl_interop_Delete(sr->interop);
-
     free(sr);
 }
 
diff --git a/modules/video_output/opengl/sub_renderer.h b/modules/video_output/opengl/sub_renderer.h
index 7b027a937b..11d2ff89fe 100644
--- a/modules/video_output/opengl/sub_renderer.h
+++ b/modules/video_output/opengl/sub_renderer.h
@@ -30,6 +30,7 @@
 
 #include "gl_api.h"
 #include "gl_common.h"
+#include "interop.h"
 
 /**
  * A subpictures renderer handles the rendering of RGB subpictures.
@@ -45,7 +46,8 @@ struct vlc_gl_sub_renderer;
  *                      texture size
  */
 struct vlc_gl_sub_renderer *
-vlc_gl_sub_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api);
+vlc_gl_sub_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
+                        struct vlc_gl_interop *interop);
 
 /**
  * Delete a subpictures renderer
diff --git a/modules/video_output/opengl/vout_helper.c b/modules/video_output/opengl/vout_helper.c
index 1d282ebee6..7ba1a13037 100644
--- a/modules/video_output/opengl/vout_helper.c
+++ b/modules/video_output/opengl/vout_helper.c
@@ -51,7 +51,10 @@ struct vout_display_opengl_t {
     vlc_gl_t   *gl;
     struct vlc_gl_api api;
 
+    struct vlc_gl_interop *interop;
     struct vlc_gl_renderer *renderer;
+
+    struct vlc_gl_interop *sub_interop;
     struct vlc_gl_sub_renderer *sub_renderer;
 };
 
@@ -140,23 +143,45 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
 
     bool b_dump_shaders = var_InheritInteger(gl, "verbose") >= 4;
 
+    vgl->interop = vlc_gl_interop_New(gl, &vgl->api, context, fmt, false);
+    if (!vgl->interop)
+    {
+        msg_Err(gl, "Could not create interop");
+        free(vgl);
+        return NULL;
+    }
+
     struct vlc_gl_renderer *renderer = vgl->renderer =
-        vlc_gl_renderer_New(gl, &vgl->api, context, fmt, b_dump_shaders);
+        vlc_gl_renderer_New(gl, &vgl->api, vgl->interop, fmt, b_dump_shaders);
     if (!vgl->renderer)
     {
         msg_Warn(gl, "Could not create renderer for %4.4s",
                  (const char *) &fmt->i_chroma);
+        vlc_gl_interop_Delete(vgl->interop);
         free(vgl);
         return NULL;
     }
 
     GL_ASSERT_NOERROR();
 
-    vgl->sub_renderer = vlc_gl_sub_renderer_New(gl, &vgl->api);
+    vgl->sub_interop = vlc_gl_interop_New(gl, &vgl->api, NULL, fmt, true);
+    if (!vgl->sub_interop)
+    {
+        msg_Err(gl, "Could not create sub interop");
+        vlc_gl_renderer_Delete(vgl->renderer);
+        vlc_gl_interop_Delete(vgl->interop);
+        free(vgl);
+        return NULL;
+    }
+
+    vgl->sub_renderer =
+        vlc_gl_sub_renderer_New(gl, &vgl->api, vgl->sub_interop);
     if (!vgl->sub_renderer)
     {
         msg_Err(gl, "Could not create sub renderer");
+        vlc_gl_interop_Delete(vgl->sub_interop);
         vlc_gl_renderer_Delete(vgl->renderer);
+        vlc_gl_interop_Delete(vgl->interop);
         free(vgl);
         return NULL;
     }
@@ -190,7 +215,10 @@ void vout_display_opengl_Delete(vout_display_opengl_t *vgl)
     vt->Flush();
 
     vlc_gl_sub_renderer_Delete(vgl->sub_renderer);
+    vlc_gl_interop_Delete(vgl->sub_interop);
+
     vlc_gl_renderer_Delete(vgl->renderer);
+    vlc_gl_interop_Delete(vgl->interop);
 
     GL_ASSERT_NOERROR();
 
-- 
2.25.0



More information about the vlc-devel mailing list