[vlc-commits] opengl: extract interop creation
Romain Vimont
git at videolan.org
Thu Feb 13 23:12:50 CET 2020
vlc | branch: master | Romain Vimont <rom1v at videolabs.io> | Mon Jan 20 16:19:47 2020 +0100| [db549a85d32392bad9ab1753a04f2be520a43b6c] | committer: Jean-Baptiste Kempf
opengl: extract interop creation
Extract interop creation into a separate function.
This will allow to create an interop without an opengl_tex_converter_t.
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=db549a85d32392bad9ab1753a04f2be520a43b6c
---
modules/video_output/opengl/vout_helper.c | 113 +++++++++++++++++-------------
1 file changed, 64 insertions(+), 49 deletions(-)
diff --git a/modules/video_output/opengl/vout_helper.c b/modules/video_output/opengl/vout_helper.c
index 914834a8e4..de5a355ae8 100644
--- a/modules/video_output/opengl/vout_helper.c
+++ b/modules/video_output/opengl/vout_helper.c
@@ -532,43 +532,27 @@ opengl_deinit_program(vout_display_opengl_t *vgl, struct prgm *prgm)
free(tc);
}
-static int
-opengl_init_program(vout_display_opengl_t *vgl, vlc_video_context *context,
- struct prgm *prgm, const video_format_t *fmt, bool subpics,
- bool b_dump_shaders)
+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 *) vgl->vt.GetString(GL_EXTENSIONS);
+ const char *glexts = (const char *) vt->GetString(GL_EXTENSIONS);
assert(glexts);
if (!glexts)
{
- msg_Err(vgl->gl, "glGetString returned NULL");
- return VLC_EGENERIC;
+ msg_Err(gl, "glGetString returned NULL");
+ return NULL;
}
- opengl_tex_converter_t *tc = calloc(1, sizeof(*tc));
- if (tc == NULL)
- return VLC_ENOMEM;
-
- struct vlc_gl_interop *interop = vlc_object_create(vgl->gl, sizeof(*interop));
+ struct vlc_gl_interop *interop = vlc_object_create(gl, sizeof(*interop));
if (!interop)
- {
- free(tc);
- return VLC_ENOMEM;
- }
-
- tc->interop = interop;
+ return NULL;
- tc->gl = vgl->gl;
- tc->vt = &vgl->vt;
- tc->b_dump_shaders = b_dump_shaders;
-#if defined(USE_OPENGL_ES2)
+#ifdef USE_OPENGL_ES2
interop->is_gles = true;
- tc->glsl_version = 100;
- tc->glsl_precision_header = "precision highp float;\n";
#else
interop->is_gles = false;
- tc->glsl_version = 120;
- tc->glsl_precision_header = "";
#endif
interop->init = opengl_interop_init_impl;
@@ -578,25 +562,8 @@ opengl_init_program(vout_display_opengl_t *vgl, vlc_video_context *context,
/* this is the only allocated field, and we don't need it */
interop->fmt.p_palette = NULL;
- interop->gl = tc->gl;
- interop->vt = tc->vt;
-
-#ifdef HAVE_LIBPLACEBO
- // Create the main libplacebo context
- if (!subpics)
- {
- tc->pl_ctx = vlc_placebo_Create(VLC_OBJECT(vgl->gl));
- if (tc->pl_ctx) {
-# if PL_API_VER >= 20
- tc->pl_sh = pl_shader_alloc(tc->pl_ctx, NULL);
-# elif PL_API_VER >= 6
- tc->pl_sh = pl_shader_alloc(tc->pl_ctx, NULL, 0);
-# else
- tc->pl_sh = pl_shader_alloc(tc->pl_ctx, NULL, 0, 0);
-# endif
- }
- }
-#endif
+ interop->gl = gl;
+ interop->vt = vt;
int ret;
if (subpics)
@@ -619,8 +586,7 @@ opengl_init_program(vout_display_opengl_t *vgl, vlc_video_context *context,
if (desc == NULL)
{
vlc_object_delete(interop);
- free(tc);
- return VLC_EGENERIC;
+ return NULL;
}
if (desc->plane_count == 0)
{
@@ -642,13 +608,62 @@ opengl_init_program(vout_display_opengl_t *vgl, vlc_video_context *context,
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,
+ bool b_dump_shaders)
+{
+ opengl_tex_converter_t *tc = calloc(1, sizeof(*tc));
+ if (tc == NULL)
+ return VLC_ENOMEM;
+
+ struct vlc_gl_interop *interop =
+ CreateInterop(vgl->gl, &vgl->vt, context, fmt, subpics);
+ if (!interop)
+ {
free(tc);
- return VLC_EGENERIC;
+ return VLC_ENOMEM;
+ }
+
+ tc->interop = interop;
+
+ tc->gl = vgl->gl;
+ tc->vt = &vgl->vt;
+ tc->b_dump_shaders = b_dump_shaders;
+#if defined(USE_OPENGL_ES2)
+ tc->glsl_version = 100;
+ tc->glsl_precision_header = "precision highp float;\n";
+#else
+ tc->glsl_version = 120;
+ tc->glsl_precision_header = "";
+#endif
+
+#ifdef HAVE_LIBPLACEBO
+ // Create the main libplacebo context
+ if (!subpics)
+ {
+ tc->pl_ctx = vlc_placebo_Create(VLC_OBJECT(vgl->gl));
+ if (tc->pl_ctx) {
+# if PL_API_VER >= 20
+ tc->pl_sh = pl_shader_alloc(tc->pl_ctx, NULL);
+# elif PL_API_VER >= 6
+ tc->pl_sh = pl_shader_alloc(tc->pl_ctx, NULL, 0);
+# else
+ tc->pl_sh = pl_shader_alloc(tc->pl_ctx, NULL, 0, 0);
+# endif
+ }
}
+#endif
prgm->tc = tc;
- ret = opengl_link_program(prgm);
+ int ret = opengl_link_program(prgm);
if (ret != VLC_SUCCESS)
{
opengl_deinit_program(vgl, prgm);
More information about the vlc-commits
mailing list