[vlc-commits] opengl: pass vlc_gl_api instead of virtual table

Romain Vimont git at videolan.org
Mon Mar 23 11:37:29 CET 2020


vlc | branch: master | Romain Vimont <rom1v at videolabs.io> | Thu Jan 30 15:29:05 2020 +0100| [7ba03dac33bbb5053c3dc5222b742717559bd239] | committer: Jean-Baptiste Kempf

opengl: pass vlc_gl_api instead of virtual table

Pass the whole structure (which will have new fields soon) to interop
and renderers, instead of the virtual table only.

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

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

 modules/video_output/opengl/interop.c      |  7 ++++---
 modules/video_output/opengl/interop.h      |  5 +++--
 modules/video_output/opengl/renderer.c     |  9 ++++++---
 modules/video_output/opengl/renderer.h     | 11 +++++++----
 modules/video_output/opengl/sub_renderer.c | 10 +++++++---
 modules/video_output/opengl/sub_renderer.h |  5 +++--
 modules/video_output/opengl/vout_helper.c  |  5 +++--
 7 files changed, 33 insertions(+), 19 deletions(-)

diff --git a/modules/video_output/opengl/interop.c b/modules/video_output/opengl/interop.c
index 74b961418f..35c26c6735 100644
--- a/modules/video_output/opengl/interop.c
+++ b/modules/video_output/opengl/interop.c
@@ -30,11 +30,11 @@
 #include "vout_helper.h"
 
 struct vlc_gl_interop *
-vlc_gl_interop_New(struct vlc_gl_t *gl, const opengl_vtable_t *vt,
+vlc_gl_interop_New(struct vlc_gl_t *gl, const struct vlc_gl_api *api,
                    vlc_video_context *context, const video_format_t *fmt,
                    bool subpics)
 {
-    const char *glexts = (const char *) vt->GetString(GL_EXTENSIONS);
+    const char *glexts = (const char *) api->vt.GetString(GL_EXTENSIONS);
     assert(glexts);
     if (!glexts)
     {
@@ -60,7 +60,8 @@ vlc_gl_interop_New(struct vlc_gl_t *gl, const opengl_vtable_t *vt,
     interop->fmt.p_palette = NULL;
 
     interop->gl = gl;
-    interop->vt = vt;
+    interop->api = api;
+    interop->vt = &api->vt;
 
     int ret;
     if (subpics)
diff --git a/modules/video_output/opengl/interop.h b/modules/video_output/opengl/interop.h
index ab054ee11a..96b34de970 100644
--- a/modules/video_output/opengl/interop.h
+++ b/modules/video_output/opengl/interop.h
@@ -109,7 +109,8 @@ struct vlc_gl_interop {
     module_t *module;
 
     vlc_gl_t *gl;
-    const opengl_vtable_t *vt;
+    const struct vlc_gl_api *api;
+    const opengl_vtable_t *vt; /* for convenience, same as &api->vt */
     GLenum tex_target;
 
     /* True if the current API is OpenGL ES, set by the caller */
@@ -157,7 +158,7 @@ struct vlc_gl_interop {
 };
 
 struct vlc_gl_interop *
-vlc_gl_interop_New(struct vlc_gl_t *gl, const opengl_vtable_t *vt,
+vlc_gl_interop_New(struct vlc_gl_t *gl, const struct vlc_gl_api *api,
                    vlc_video_context *context, const video_format_t *fmt,
                    bool subpics);
 
diff --git a/modules/video_output/opengl/renderer.c b/modules/video_output/opengl/renderer.c
index 416530ffea..69332defb1 100644
--- a/modules/video_output/opengl/renderer.c
+++ b/modules/video_output/opengl/renderer.c
@@ -310,7 +310,7 @@ vlc_gl_renderer_Delete(struct vlc_gl_renderer *renderer)
 
     vlc_gl_interop_Delete(interop);
     if (renderer->program_id != 0)
-        renderer->vt->DeleteProgram(renderer->program_id);
+        vt->DeleteProgram(renderer->program_id);
 
 #ifdef HAVE_LIBPLACEBO
     FREENULL(renderer->uloc.pl_vars);
@@ -322,16 +322,18 @@ vlc_gl_renderer_Delete(struct vlc_gl_renderer *renderer)
 }
 
 struct vlc_gl_renderer *
-vlc_gl_renderer_New(vlc_gl_t *gl, const opengl_vtable_t *vt,
+vlc_gl_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
                     vlc_video_context *context, const video_format_t *fmt,
                     bool supports_npot, bool b_dump_shaders)
 {
+    const opengl_vtable_t *vt = &api->vt;
+
     struct vlc_gl_renderer *renderer = calloc(1, sizeof(*renderer));
     if (!renderer)
         return NULL;
 
     struct vlc_gl_interop *interop =
-        vlc_gl_interop_New(gl, vt, context, fmt, false);
+        vlc_gl_interop_New(gl, api, context, fmt, false);
     if (!interop)
     {
         free(renderer);
@@ -341,6 +343,7 @@ vlc_gl_renderer_New(vlc_gl_t *gl, const opengl_vtable_t *vt,
     renderer->interop = interop;
 
     renderer->gl = gl;
+    renderer->api = api;
     renderer->vt = vt;
     renderer->b_dump_shaders = b_dump_shaders;
 #if defined(USE_OPENGL_ES2)
diff --git a/modules/video_output/opengl/renderer.h b/modules/video_output/opengl/renderer.h
index a8da814761..e161e7eb52 100644
--- a/modules/video_output/opengl/renderer.h
+++ b/modules/video_output/opengl/renderer.h
@@ -25,6 +25,8 @@
 #include <vlc_codec.h>
 #include <vlc_opengl.h>
 #include <vlc_plugin.h>
+
+#include "gl_api.h"
 #include "gl_common.h"
 #include "interop.h"
 
@@ -43,8 +45,9 @@ struct vlc_gl_renderer
     /* libplacebo context, created by the caller (optional) */
     struct pl_context *pl_ctx;
 
-    /* Function pointers to OpenGL functions, set by the caller */
-    const opengl_vtable_t *vt;
+    /* Set by the caller */
+    const struct vlc_gl_api *api;
+    const opengl_vtable_t *vt; /* for convenience, same as &api->vt */
 
     /* True to dump shaders, set by the caller */
     bool b_dump_shaders;
@@ -152,7 +155,7 @@ struct vlc_gl_renderer
  * Create a new renderer
  *
  * \param gl the GL context
- * \param vt the OpenGL functions vtable
+ * \param api the OpenGL API
  * \param context the video context
  * \param fmt the video format
  * \param supports_npot indicate if the implementation supports non-power-of-2
@@ -160,7 +163,7 @@ struct vlc_gl_renderer
  * \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 opengl_vtable_t *vt,
+vlc_gl_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
                     vlc_video_context *context, const video_format_t *fmt,
                     bool supports_npot, bool dump_shaders);
 
diff --git a/modules/video_output/opengl/sub_renderer.c b/modules/video_output/opengl/sub_renderer.c
index e434f2ee30..8313b81caa 100644
--- a/modules/video_output/opengl/sub_renderer.c
+++ b/modules/video_output/opengl/sub_renderer.c
@@ -60,7 +60,8 @@ typedef struct {
 struct vlc_gl_sub_renderer
 {
     vlc_gl_t *gl;
-    const opengl_vtable_t *vt;
+    const struct vlc_gl_api *api;
+    const opengl_vtable_t *vt; /* for convenience, same as &api->vt */
 
     struct vlc_gl_interop *interop;
 
@@ -112,16 +113,18 @@ FetchLocations(struct vlc_gl_sub_renderer *sr)
 }
 
 struct vlc_gl_sub_renderer *
-vlc_gl_sub_renderer_New(vlc_gl_t *gl, const opengl_vtable_t *vt,
+vlc_gl_sub_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
                         bool supports_npot)
 {
+    const opengl_vtable_t *vt = &api->vt;
+
     struct vlc_gl_sub_renderer *sr = malloc(sizeof(*sr));
     if (!sr)
         return NULL;
 
     video_format_t fmt;
     video_format_Init(&fmt, VLC_CODEC_RGB32);
-    sr->interop = vlc_gl_interop_New(gl, vt, NULL, &fmt, true);
+    sr->interop = vlc_gl_interop_New(gl, api, NULL, &fmt, true);
     if (!sr->interop)
         goto error_1;
 
@@ -129,6 +132,7 @@ vlc_gl_sub_renderer_New(vlc_gl_t *gl, const opengl_vtable_t *vt,
     assert(!sr->interop->handle_texs_gen);
 
     sr->gl = gl;
+    sr->api = api;
     sr->vt = vt;
     sr->supports_npot = supports_npot;
     sr->region_count = 0;
diff --git a/modules/video_output/opengl/sub_renderer.h b/modules/video_output/opengl/sub_renderer.h
index 48c0ebea59..cfd1bc79d2 100644
--- a/modules/video_output/opengl/sub_renderer.h
+++ b/modules/video_output/opengl/sub_renderer.h
@@ -28,6 +28,7 @@
 #include <vlc_common.h>
 #include <vlc_opengl.h>
 
+#include "gl_api.h"
 #include "gl_common.h"
 
 /**
@@ -39,12 +40,12 @@ struct vlc_gl_sub_renderer;
  * Create a new subpictures renderer
  *
  * \param gl the GL context
- * \param vt the OpenGL functions vtable
+ * \param api the OpenGL API
  * \param supports_npot indicate if the implementation supports non-power-of-2
  *                      texture size
  */
 struct vlc_gl_sub_renderer *
-vlc_gl_sub_renderer_New(vlc_gl_t *gl, const opengl_vtable_t *vt,
+vlc_gl_sub_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
                         bool supports_npot);
 
 /**
diff --git a/modules/video_output/opengl/vout_helper.c b/modules/video_output/opengl/vout_helper.c
index b29de3534d..72c5865f8d 100644
--- a/modules/video_output/opengl/vout_helper.c
+++ b/modules/video_output/opengl/vout_helper.c
@@ -152,7 +152,7 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
     bool b_dump_shaders = var_InheritInteger(gl, "verbose") >= 4;
 
     struct vlc_gl_renderer *renderer = vgl->renderer =
-        vlc_gl_renderer_New(gl, vt, context, fmt, supports_npot,
+        vlc_gl_renderer_New(gl, &vgl->api, context, fmt, supports_npot,
                             b_dump_shaders);
     if (!vgl->renderer)
     {
@@ -164,7 +164,8 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
 
     GL_ASSERT_NOERROR(vt);
 
-    vgl->sub_renderer = vlc_gl_sub_renderer_New(gl, vt, supports_npot);
+    vgl->sub_renderer = vlc_gl_sub_renderer_New(gl, &vgl->api,
+                                                supports_npot);
     if (!vgl->sub_renderer)
     {
         msg_Err(gl, "Could not create sub renderer");



More information about the vlc-commits mailing list