[vlc-devel] [PATCH v4 18/20] opengl: init filters framebuffers in a second pass

Romain Vimont rom1v at videolabs.io
Tue Jul 7 12:34:01 CEST 2020


This paves the way to initialize multisample framebuffers, which depend
on whether the filter is the last.

Co-authored-by: Alexandre Janniaux <ajanni at videolabs.io>
---
 modules/video_output/opengl/filters.c     | 59 +++++++++++++----------
 modules/video_output/opengl/filters.h     | 12 +++++
 modules/video_output/opengl/vout_helper.c |  7 +++
 3 files changed, 53 insertions(+), 25 deletions(-)

diff --git a/modules/video_output/opengl/filters.c b/modules/video_output/opengl/filters.c
index 41a023eb20..497ff2af68 100644
--- a/modules/video_output/opengl/filters.c
+++ b/modules/video_output/opengl/filters.c
@@ -215,35 +215,21 @@ vlc_gl_filters_Append(struct vlc_gl_filters *filters, const char *name,
      */
     assert(!filter->config.blend || !priv->sampler);
 
-    if (filter->config.blend && !prev_filter)
-    {
-        /* We cannot blend with nothing, so insert a "draw" filter to draw the
-         * input picture to blend with. */
-        struct vlc_gl_filter *draw =
-            vlc_gl_filters_Append(filters, "draw", NULL);
-        if (!draw)
-        {
-            vlc_gl_filter_Delete(filter);
-            return NULL;
-        }
-    }
-    else if (!filter->config.blend && prev_filter)
+    if (filter->config.blend)
     {
-        /* It was the last non-blend filter before we append this one */
-        assert(!prev_filter->has_framebuffer_out);
-
-        /* Every non-blend filter needs its own framebuffer, except the last
-         * one */
-        ret = InitFramebufferOut(prev_filter);
-        if (ret != VLC_SUCCESS)
+        if (!prev_filter)
         {
-            vlc_gl_filter_Delete(filter);
-            return NULL;
+            /* We cannot blend with nothing, so insert a "draw" filter to draw
+             * the input picture to blend with. */
+            struct vlc_gl_filter *draw =
+                vlc_gl_filters_Append(filters, "draw", NULL);
+            if (!draw)
+            {
+                vlc_gl_filter_Delete(filter);
+                return NULL;
+            }
         }
-    }
 
-    if (filter->config.blend)
-    {
         /* Append as a subfilter of a non-blend filter */
         struct vlc_gl_filter_priv *last_filter =
             vlc_list_last_entry_or_null(&filters->list,
@@ -268,6 +254,29 @@ vlc_gl_filters_Append(struct vlc_gl_filters *filters, const char *name,
     return filter;
 }
 
+int
+vlc_gl_filters_InitFramebuffers(struct vlc_gl_filters *filters)
+{
+    struct vlc_gl_filter_priv *priv;
+    vlc_list_foreach(priv, &filters->list, node)
+    {
+        bool is_last = vlc_list_is_last(&priv->node, &filters->list);
+        if (!is_last)
+        {
+            /* It was the last non-blend filter before we append this one */
+            assert(!priv->has_framebuffer_out);
+
+            /* Every non-blend filter needs its own framebuffer, except the last
+             * one */
+            int ret = InitFramebufferOut(priv);
+            if (ret != VLC_SUCCESS)
+                return ret;
+        }
+    }
+
+    return VLC_SUCCESS;
+}
+
 int
 vlc_gl_filters_UpdatePicture(struct vlc_gl_filters *filters,
                              picture_t *picture)
diff --git a/modules/video_output/opengl/filters.h b/modules/video_output/opengl/filters.h
index c7b8ec3942..de2807cee7 100644
--- a/modules/video_output/opengl/filters.h
+++ b/modules/video_output/opengl/filters.h
@@ -67,6 +67,18 @@ struct vlc_gl_filter *
 vlc_gl_filters_Append(struct vlc_gl_filters *filters, const char *name,
                       const config_chain_t *config);
 
+/**
+ * Init the framebuffers for the appended filters.
+ *
+ * This function must be called once after all filters have been appended. It
+ * is an error to call vlc_gl_filters_Append() after this function.
+ *
+ * \param filters the filter chain
+ * \return VLC_SUCCESS on success, another value on error
+ */
+int
+vlc_gl_filters_InitFramebuffers(struct vlc_gl_filters *filters);
+
 /**
  * Update the input picture to pass to the first filter
  *
diff --git a/modules/video_output/opengl/vout_helper.c b/modules/video_output/opengl/vout_helper.c
index f25ccbd962..ea4bec2af7 100644
--- a/modules/video_output/opengl/vout_helper.c
+++ b/modules/video_output/opengl/vout_helper.c
@@ -164,6 +164,13 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
      * forward SetViewpoint() */
     vgl->renderer = renderer_filter->sys;
 
+    ret = vlc_gl_filters_InitFramebuffers(vgl->filters);
+    if (ret != VLC_SUCCESS)
+    {
+        msg_Err(gl, "Could not init filters framebuffers");
+        goto delete_filters;
+    }
+
     vgl->sub_interop = vlc_gl_interop_NewForSubpictures(gl, api);
     if (!vgl->sub_interop)
     {
-- 
2.27.0



More information about the vlc-devel mailing list