[vlc-commits] opengl: apply viewport on filters

Romain Vimont git at videolan.org
Thu Sep 10 15:41:52 CEST 2020


vlc | branch: master | Romain Vimont <rom1v at videolabs.io> | Tue Jul  7 12:33:58 2020 +0200| [68e26f1e69ca0cf3106ddab2c0f272f8e5379c6f] | committer: Alexandre Janniaux

opengl: apply viewport on filters

The requested viewport must be applied only on filters which draw
directly to the output (from the last non-blend filter to the end).

Co-authored-by: Alexandre Janniaux <ajanni at videolabs.io>
Signed-off-by: Alexandre Janniaux <ajanni at videolabs.io>

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

 modules/video_output/opengl/filters.c     | 29 +++++++++++++++++++++++++++++
 modules/video_output/opengl/filters.h     |  7 +++++++
 modules/video_output/opengl/vout_helper.c |  3 +--
 3 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/modules/video_output/opengl/filters.c b/modules/video_output/opengl/filters.c
index 4e5dd9a1ae..a8724e474b 100644
--- a/modules/video_output/opengl/filters.c
+++ b/modules/video_output/opengl/filters.c
@@ -43,6 +43,13 @@ struct vlc_gl_filters {
     struct vlc_gl_interop *interop;
 
     struct vlc_list list; /**< list of vlc_gl_filter.node */
+
+    struct vlc_gl_filters_viewport {
+        int x;
+        int y;
+        unsigned width;
+        unsigned height;
+    } viewport;
 };
 
 struct vlc_gl_filters *
@@ -57,6 +64,9 @@ vlc_gl_filters_New(struct vlc_gl_t *gl, const struct vlc_gl_api *api,
     filters->api = api;
     filters->interop = interop;
     vlc_list_init(&filters->list);
+
+    memset(&filters->viewport, 0, sizeof(filters->viewport));
+
     return filters;
 }
 
@@ -301,6 +311,15 @@ vlc_gl_filters_Draw(struct vlc_gl_filters *filters)
 
         vt->BindFramebuffer(GL_DRAW_FRAMEBUFFER, draw_fb);
 
+        if (vlc_list_is_last(&priv->node, &filters->list))
+        {
+            /* The output viewport must be applied on the last filter */
+            struct vlc_gl_filters_viewport *vp = &filters->viewport;
+            vt->Viewport(vp->x, vp->y, vp->width, vp->height);
+        }
+        else
+            vt->Viewport(0, 0, priv->size_out.width, priv->size_out.height);
+
         struct vlc_gl_filter *filter = &priv->filter;
         int ret = filter->ops->draw(filter);
         if (ret != VLC_SUCCESS)
@@ -323,3 +342,13 @@ vlc_gl_filters_Draw(struct vlc_gl_filters *filters)
 
     return VLC_SUCCESS;
 }
+
+void
+vlc_gl_filters_SetViewport(struct vlc_gl_filters *filters, int x, int y,
+                           unsigned width, unsigned height)
+{
+    filters->viewport.x = x;
+    filters->viewport.y = y;
+    filters->viewport.width = width;
+    filters->viewport.height = height;
+}
diff --git a/modules/video_output/opengl/filters.h b/modules/video_output/opengl/filters.h
index 26b89b407c..3541bf0076 100644
--- a/modules/video_output/opengl/filters.h
+++ b/modules/video_output/opengl/filters.h
@@ -86,4 +86,11 @@ vlc_gl_filters_UpdatePicture(struct vlc_gl_filters *filters,
 int
 vlc_gl_filters_Draw(struct vlc_gl_filters *filters);
 
+/**
+ * Set the viewport.
+ */
+void
+vlc_gl_filters_SetViewport(struct vlc_gl_filters *filters, int x, int y,
+                           unsigned width, unsigned height);
+
 #endif
diff --git a/modules/video_output/opengl/vout_helper.c b/modules/video_output/opengl/vout_helper.c
index e670d88e4a..d38b5caa30 100644
--- a/modules/video_output/opengl/vout_helper.c
+++ b/modules/video_output/opengl/vout_helper.c
@@ -246,8 +246,7 @@ void vout_display_opengl_SetWindowAspectRatio(vout_display_opengl_t *vgl,
 void vout_display_opengl_Viewport(vout_display_opengl_t *vgl, int x, int y,
                                   unsigned width, unsigned height)
 {
-    const opengl_vtable_t *vt = &vgl->api.vt;
-    vt->Viewport(x, y, width, height);
+    vlc_gl_filters_SetViewport(vgl->filters, x, y, width, height);
 }
 
 int vout_display_opengl_Prepare(vout_display_opengl_t *vgl,



More information about the vlc-commits mailing list