[vlc-devel] [PATCH v3 01/22] opengl: introduce OpenGL filter API

Romain Vimont rom1v at videolabs.io
Mon Jul 6 12:46:54 CEST 2020


Expose a filter API, and make renderer a specific filter.

Co-authored-by: Alexandre Janniaux <ajanni at videolabs.io>
Co-authored-by: Maxime Meissonnier <mmeisson at outlook.fr>
---
 modules/video_output/opengl/Makefile.am   |  1 +
 modules/video_output/opengl/filter.h      | 42 +++++++++++++++++++++++
 modules/video_output/opengl/renderer.c    | 16 +++++++--
 modules/video_output/opengl/renderer.h    | 12 +++----
 modules/video_output/opengl/vout_helper.c |  4 ++-
 5 files changed, 64 insertions(+), 11 deletions(-)
 create mode 100644 modules/video_output/opengl/filter.h

diff --git a/modules/video_output/opengl/Makefile.am b/modules/video_output/opengl/Makefile.am
index a11bcdf3ee..3774737129 100644
--- a/modules/video_output/opengl/Makefile.am
+++ b/modules/video_output/opengl/Makefile.am
@@ -1,4 +1,5 @@
 OPENGL_COMMONSOURCES = video_output/opengl/vout_helper.c \
+       video_output/opengl/filter.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.h b/modules/video_output/opengl/filter.h
new file mode 100644
index 0000000000..f4b3f8bbf2
--- /dev/null
+++ b/modules/video_output/opengl/filter.h
@@ -0,0 +1,42 @@
+/*****************************************************************************
+ * filter.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_H
+#define VLC_GL_FILTER_H
+
+struct vlc_gl_filter;
+
+struct vlc_gl_filter_ops {
+    /**
+     * Draw the result of the filter to the current framebuffer
+     */
+    int (*draw)(struct vlc_gl_filter *filter);
+};
+
+/**
+ * OpenGL filter, in charge of a rendering pass.
+ */
+struct vlc_gl_filter {
+    const struct vlc_gl_filter_ops *ops;
+    void *sys;
+};
+
+#endif
diff --git a/modules/video_output/opengl/renderer.c b/modules/video_output/opengl/renderer.c
index aa51f8b3a3..590fc3e46c 100644
--- a/modules/video_output/opengl/renderer.c
+++ b/modules/video_output/opengl/renderer.c
@@ -37,6 +37,7 @@
 #include <vlc_es.h>
 #include <vlc_picture.h>
 
+#include "filter.h"
 #include "gl_util.h"
 #include "internal.h"
 #include "vout_helper.h"
@@ -321,6 +322,9 @@ vlc_gl_renderer_Delete(struct vlc_gl_renderer *renderer)
 
 static int SetupCoords(struct vlc_gl_renderer *renderer);
 
+static int
+Draw(struct vlc_gl_filter *filter);
+
 struct vlc_gl_renderer *
 vlc_gl_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
                     struct vlc_gl_sampler *sampler)
@@ -332,6 +336,12 @@ vlc_gl_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
     if (!renderer)
         return NULL;
 
+    static const struct vlc_gl_filter_ops filter_ops = {
+        .draw = Draw,
+    };
+    renderer->filter.ops = &filter_ops;
+    renderer->filter.sys = renderer;
+
     renderer->sampler = sampler;
 
     renderer->gl = gl;
@@ -735,9 +745,11 @@ static int SetupCoords(struct vlc_gl_renderer *renderer)
     return VLC_SUCCESS;
 }
 
-int
-vlc_gl_renderer_Draw(struct vlc_gl_renderer *renderer)
+static int
+Draw(struct vlc_gl_filter *filter)
 {
+    struct vlc_gl_renderer *renderer = filter->sys;
+
     const opengl_vtable_t *vt = renderer->vt;
 
     vt->Clear(GL_COLOR_BUFFER_BIT);
diff --git a/modules/video_output/opengl/renderer.h b/modules/video_output/opengl/renderer.h
index 7130cfb262..9aec83d2e2 100644
--- a/modules/video_output/opengl/renderer.h
+++ b/modules/video_output/opengl/renderer.h
@@ -26,6 +26,7 @@
 #include <vlc_opengl.h>
 #include <vlc_plugin.h>
 
+#include "filter.h"
 #include "gl_api.h"
 #include "gl_common.h"
 #include "interop.h"
@@ -47,6 +48,9 @@ struct vlc_gl_renderer
     const struct vlc_gl_api *api;
     const opengl_vtable_t *vt; /* for convenience, same as &api->vt */
 
+    /* vlc_gl_renderer "extends" vlc_gl_filter */
+    struct vlc_gl_filter filter;
+
     /* True to dump shaders */
     bool dump_shaders;
 
@@ -108,14 +112,6 @@ vlc_gl_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
 void
 vlc_gl_renderer_Delete(struct vlc_gl_renderer *renderer);
 
-/**
- * Draw the prepared picture
- *
- * \param sr the renderer
- */
-int
-vlc_gl_renderer_Draw(struct vlc_gl_renderer *renderer);
-
 int
 vlc_gl_renderer_SetViewpoint(struct vlc_gl_renderer *renderer,
                              const vlc_viewpoint_t *p_vp);
diff --git a/modules/video_output/opengl/vout_helper.c b/modules/video_output/opengl/vout_helper.c
index b6105dd062..993bb405f1 100644
--- a/modules/video_output/opengl/vout_helper.c
+++ b/modules/video_output/opengl/vout_helper.c
@@ -267,7 +267,9 @@ int vout_display_opengl_Display(vout_display_opengl_t *vgl)
        OpenGL providers can call vout_display_opengl_Display to force redraw.
        Currently, the OS X provider uses it to get a smooth window resizing */
 
-    int ret = vlc_gl_renderer_Draw(vgl->renderer);
+    /* Retrieve the "super-class" (renderer "extends" 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