[vlc-devel] [PATCH 02/27] opengl: add filter private part

Romain Vimont rom1v at videolabs.io
Thu Jun 25 14:22:49 CEST 2020


The filter API will be used by external modules.

Create a private struct to store data private to the OpenGL module.
---
 modules/video_output/opengl/Makefile.am   |  2 +
 modules/video_output/opengl/filter.c      | 47 +++++++++++++++++++++++
 modules/video_output/opengl/filter_priv.h | 42 ++++++++++++++++++++
 modules/video_output/opengl/renderer.c    | 16 ++++++--
 modules/video_output/opengl/renderer.h    |  2 +-
 modules/video_output/opengl/vout_helper.c |  2 +-
 6 files changed, 106 insertions(+), 5 deletions(-)
 create mode 100644 modules/video_output/opengl/filter.c
 create mode 100644 modules/video_output/opengl/filter_priv.h

diff --git a/modules/video_output/opengl/Makefile.am b/modules/video_output/opengl/Makefile.am
index 3be82c458c..f1ab95be87 100644
--- a/modules/video_output/opengl/Makefile.am
+++ b/modules/video_output/opengl/Makefile.am
@@ -1,5 +1,7 @@
 OPENGL_COMMONSOURCES = video_output/opengl/vout_helper.c \
+       video_output/opengl/filter.c \
        video_output/opengl/filter.h \
+       video_output/opengl/filter_priv.h \
        video_output/opengl/gl_api.c \
        video_output/opengl/gl_api.h \
        video_output/opengl/gl_common.h \
diff --git a/modules/video_output/opengl/filter.c b/modules/video_output/opengl/filter.c
new file mode 100644
index 0000000000..c889768479
--- /dev/null
+++ b/modules/video_output/opengl/filter.c
@@ -0,0 +1,47 @@
+/*****************************************************************************
+ * filter.c
+ *****************************************************************************
+ * Copyright (C) 2020 VLC authors and VideoLAN
+ * Copyright (C) 2020 Videolabs
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "filter_priv.h"
+
+struct vlc_gl_filter *
+vlc_gl_filter_New(void)
+{
+    struct vlc_gl_filter_priv *priv = malloc(sizeof(*priv));
+    if (!priv)
+        return NULL;
+
+    struct vlc_gl_filter *filter = &priv->filter;
+    filter->ops = NULL;
+    filter->sys = NULL;
+
+    return filter;
+}
+
+void
+vlc_gl_filter_Delete(struct vlc_gl_filter *filter)
+{
+    struct vlc_gl_filter_priv *priv = vlc_gl_filter_PRIV(filter);
+    free(priv);
+}
diff --git a/modules/video_output/opengl/filter_priv.h b/modules/video_output/opengl/filter_priv.h
new file mode 100644
index 0000000000..ffc54e0ca8
--- /dev/null
+++ b/modules/video_output/opengl/filter_priv.h
@@ -0,0 +1,42 @@
+/*****************************************************************************
+ * filter_priv.h
+ *****************************************************************************
+ * Copyright (C) 2020 VLC authors and VideoLAN
+ * Copyright (C) 2020 Videolabs
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef VLC_GL_FILTER_PRIV_H
+#define VLC_GL_FILTER_PRIV_H
+
+#include <vlc_common.h>
+
+#include "filter.h"
+
+struct vlc_gl_filter_priv {
+    struct vlc_gl_filter filter;
+};
+
+#define vlc_gl_filter_PRIV(filter) \
+    container_of(filter, struct vlc_gl_filter_priv, filter)
+
+struct vlc_gl_filter *
+vlc_gl_filter_New(void);
+
+void
+vlc_gl_filter_Delete(struct vlc_gl_filter *filter);
+
+#endif
diff --git a/modules/video_output/opengl/renderer.c b/modules/video_output/opengl/renderer.c
index 590fc3e46c..209d732764 100644
--- a/modules/video_output/opengl/renderer.c
+++ b/modules/video_output/opengl/renderer.c
@@ -37,7 +37,7 @@
 #include <vlc_es.h>
 #include <vlc_picture.h>
 
-#include "filter.h"
+#include "filter_priv.h"
 #include "gl_util.h"
 #include "internal.h"
 #include "vout_helper.h"
@@ -310,6 +310,8 @@ vlc_gl_renderer_Delete(struct vlc_gl_renderer *renderer)
 {
     const opengl_vtable_t *vt = renderer->vt;
 
+    vlc_gl_filter_Delete(renderer->filter);
+
     vt->DeleteBuffers(1, &renderer->vertex_buffer_object);
     vt->DeleteBuffers(1, &renderer->index_buffer_object);
     vt->DeleteBuffers(1, &renderer->texture_buffer_object);
@@ -336,12 +338,20 @@ vlc_gl_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
     if (!renderer)
         return NULL;
 
+    struct vlc_gl_filter *filter = vlc_gl_filter_New();
+    if (!filter)
+    {
+        free(renderer);
+        return NULL;
+    }
+
     static const struct vlc_gl_filter_ops filter_ops = {
         .draw = Draw,
     };
-    renderer->filter.ops = &filter_ops;
-    renderer->filter.sys = renderer;
+    filter->ops = &filter_ops;
+    filter->sys = renderer;
 
+    renderer->filter = filter;
     renderer->sampler = sampler;
 
     renderer->gl = gl;
diff --git a/modules/video_output/opengl/renderer.h b/modules/video_output/opengl/renderer.h
index 9aec83d2e2..76f12b6070 100644
--- a/modules/video_output/opengl/renderer.h
+++ b/modules/video_output/opengl/renderer.h
@@ -49,7 +49,7 @@ struct vlc_gl_renderer
     const opengl_vtable_t *vt; /* for convenience, same as &api->vt */
 
     /* vlc_gl_renderer "extends" vlc_gl_filter */
-    struct vlc_gl_filter filter;
+    struct vlc_gl_filter *filter;
 
     /* True to dump shaders */
     bool dump_shaders;
diff --git a/modules/video_output/opengl/vout_helper.c b/modules/video_output/opengl/vout_helper.c
index 993bb405f1..581df6b319 100644
--- a/modules/video_output/opengl/vout_helper.c
+++ b/modules/video_output/opengl/vout_helper.c
@@ -268,7 +268,7 @@ int vout_display_opengl_Display(vout_display_opengl_t *vgl)
        Currently, the OS X provider uses it to get a smooth window resizing */
 
     /* Retrieve the "super-class" (renderer "extends" filter) */
-    struct vlc_gl_filter *renderer_filter = &vgl->renderer->filter;
+    struct vlc_gl_filter *renderer_filter = vgl->renderer->filter;
     int ret = renderer_filter->ops->draw(renderer_filter);
     if (ret != VLC_SUCCESS)
         return ret;
-- 
2.27.0



More information about the vlc-devel mailing list