[vlc-devel] [PATCH 5/5] opengl: accept vout format update

Romain Vimont rom1v at videolabs.io
Tue Oct 20 14:32:46 CEST 2020


If the core requests to update the vout format (because it added filters
producing pictures in a different format), recreate the interop and the
filters to accept the new format without an additional converter.
---
 modules/video_output/opengl/display.c     | 18 ++++++++-
 modules/video_output/opengl/vout_helper.c | 45 +++++++++++++++++++++++
 modules/video_output/opengl/vout_helper.h |  4 ++
 3 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/modules/video_output/opengl/display.c b/modules/video_output/opengl/display.c
index 82e0dc5156..f8451416f7 100644
--- a/modules/video_output/opengl/display.c
+++ b/modules/video_output/opengl/display.c
@@ -93,8 +93,24 @@ static int SetViewpoint(vout_display_t *vd, const vlc_viewpoint_t *vp)
     return vout_display_opengl_SetViewpoint (sys->vgl, vp);
 }
 
+static int
+UpdateFormat(vout_display_t *vd, video_format_t *fmt, vlc_video_context *ctx)
+{
+    vout_display_sys_t *sys = vd->sys;
+
+    int ret = vlc_gl_MakeCurrent(sys->gl);
+    if (ret != VLC_SUCCESS)
+        return ret;
+
+    ret = vout_display_opengl_UpdateFormat(sys->vgl, fmt, ctx);
+
+    vlc_gl_ReleaseCurrent(sys->gl);
+
+    return ret;
+}
+
 static const struct vlc_display_operations ops = {
-    Close, PictureRender, PictureDisplay, Control, NULL, SetViewpoint, NULL,
+    Close, PictureRender, PictureDisplay, Control, NULL, SetViewpoint, UpdateFormat,
 };
 
 /**
diff --git a/modules/video_output/opengl/vout_helper.c b/modules/video_output/opengl/vout_helper.c
index 2f7429fc71..82261ebeef 100644
--- a/modules/video_output/opengl/vout_helper.c
+++ b/modules/video_output/opengl/vout_helper.c
@@ -270,6 +270,51 @@ free_vgl:
     return NULL;
 }
 
+int vout_display_opengl_UpdateFormat(vout_display_opengl_t *vgl,
+                                     video_format_t *fmt,
+                                     vlc_video_context *ctx)
+{
+    /* If the format can't be changed, the state must stay valid to accept the
+     * initial format. */
+
+    vlc_gl_t *gl = vgl->gl;
+    const struct vlc_gl_api *api = &vgl->api;
+
+    struct vlc_gl_interop *interop = CreateInterop(gl, api, ctx, fmt);
+    if (!interop)
+        return VLC_EGENERIC;
+
+    struct vlc_gl_renderer *renderer;
+    struct vlc_gl_filters *filters = CreateFilters(gl, api, interop, &renderer);
+    if (!filters)
+    {
+        vlc_gl_interop_Delete(interop);
+        return VLC_EGENERIC;
+    }
+
+    /* re-assign the state to the new filters and renderer instances */
+    vlc_gl_filters_SetViewport(filters, vgl->memory.viewport.x,
+                                        vgl->memory.viewport.y,
+                                        vgl->memory.viewport.width,
+                                        vgl->memory.viewport.height);
+
+    vlc_gl_renderer_SetWindowAspectRatio(renderer,
+                                         vgl->memory.window_aspect_ratio);
+
+    vlc_gl_renderer_SetViewpoint(renderer, &vgl->memory.viewpoint);
+
+    /* We created everything necessary, it worked, now the old ones could be
+     * replaced. */
+    vlc_gl_filters_Delete(vgl->filters);
+    vlc_gl_interop_Delete(vgl->interop);
+
+    vgl->interop = interop;
+    vgl->filters = filters;
+    vgl->renderer = renderer;
+
+    return VLC_SUCCESS;
+}
+
 void vout_display_opengl_Delete(vout_display_opengl_t *vgl)
 {
     const opengl_vtable_t *vt = &vgl->api.vt;
diff --git a/modules/video_output/opengl/vout_helper.h b/modules/video_output/opengl/vout_helper.h
index 482eabb554..a2675f3077 100644
--- a/modules/video_output/opengl/vout_helper.h
+++ b/modules/video_output/opengl/vout_helper.h
@@ -105,4 +105,8 @@ int vout_display_opengl_Prepare(vout_display_opengl_t *vgl,
                                 picture_t *picture, subpicture_t *subpicture);
 int vout_display_opengl_Display(vout_display_opengl_t *vgl);
 
+int vout_display_opengl_UpdateFormat(vout_display_opengl_t *vgl,
+                                     video_format_t *fmt,
+                                     vlc_video_context *ctx);
+
 #endif
-- 
2.28.0



More information about the vlc-devel mailing list