[vlc-devel] [PATCH 7/7] egl_display: add GBM platform support

Rémi Denis-Courmont remi at remlab.net
Wed Mar 3 17:48:12 UTC 2021


Le keskiviikkona 3. maaliskuuta 2021, 19.36.40 EET Romain Vimont a écrit :
> From: Alexandre Janniaux <ajanni at videolabs.io>
> 
> GBM platform allows to provide an EGL context even without display
> server.
> 
> Co-authored-by: Romain Vimont <rom1v at videolabs.io>
> ---
>  configure.ac                                  |  18 +++
>  modules/video_output/opengl/Makefile.am       |   9 ++
>  modules/video_output/opengl/egl_display_gbm.c | 106 ++++++++++++++++++
>  3 files changed, 133 insertions(+)
>  create mode 100644 modules/video_output/opengl/egl_display_gbm.c
> 
> diff --git a/configure.ac b/configure.ac
> index a82c956c70..cd546da9ca 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -4464,6 +4464,24 @@ AS_IF([test "${enable_osx_notifications}" != "no"], [
> VLC_ADD_PLUGIN([osx_notifications])
>  ])
> 
> +dnl
> +dnl Check for GBM
> +dnl
> +AC_ARG_ENABLE([gbm],
> +  AS_HELP_STRING([--enable-gbm],
> +    [Use GBM for egl_pbuffer (default enabled)]))
> +have_gbm="no"
> +AS_IF([test "${enable_gbm}" != "no"], [
> +  PKG_CHECK_MODULES([GBM], [gbm], [have_gbm="yes"], [
> +    AS_IF([test -n "${enable_gbm}"], [
> +      AC_MSG_ERROR([${GBM_PKG_ERRORS}.])
> +    ], [
> +      AC_MSG_WARN([${GBM_PKG_ERRORS}.])
> +    ])
> +  ])
> +])
> +AM_CONDITIONAL([HAVE_GBM], [test "${have_gbm}" = "yes"])
> +
>  dnl
>  dnl Libnotify notification plugin
>  dnl
> diff --git a/modules/video_output/opengl/Makefile.am
> b/modules/video_output/opengl/Makefile.am index c7cbdedfb6..d496093d75
> 100644
> --- a/modules/video_output/opengl/Makefile.am
> +++ b/modules/video_output/opengl/Makefile.am
> @@ -96,6 +96,15 @@ if HAVE_EGL
>  vout_LTLIBRARIES += libegl_display_generic_plugin.la
>  endif
> 
> +libegl_display_gbm_plugin_la_SOURCES =
> video_output/opengl/egl_display_gbm.c
> +libegl_display_gbm_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) $(EGL_FLAGS)
> $(GBM_CFLAGS) +libegl_display_gbm_plugin_la_LIBADD = $(EGL_LIBS)
> $(GBM_LIBS)
> +if HAVE_EGL
> +if HAVE_GBM
> +vout_LTLIBRARIES += libegl_display_gbm_plugin.la
> +endif
> +endif
> +
>  libegl_pbuffer_filter_plugin_la_SOURCES = video_filter/egl_pbuffer.c \
>      video_output/opengl/egl_display.c
>  libegl_pbuffer_filter_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) $(EGL_FLAGS)
> diff --git a/modules/video_output/opengl/egl_display_gbm.c
> b/modules/video_output/opengl/egl_display_gbm.c new file mode 100644
> index 0000000000..53049fc5dd
> --- /dev/null
> +++ b/modules/video_output/opengl/egl_display_gbm.c
> @@ -0,0 +1,106 @@
> +/**************************************************************************
> *** + * egl_display_gbm.c
> +
> ***************************************************************************
> ** + * Copyright (C) 2021 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 <vlc_common.h>
> +#include <vlc_plugin.h>
> +#include <vlc_opengl.h>
> +#include <vlc_fs.h>
> +#include <fcntl.h>
> +#include <assert.h>
> +
> +#include <EGL/egl.h>
> +#include <EGL/eglext.h>
> +#include <gbm.h>
> +
> +#include "egl_display.h"
> +
> +struct sys
> +{
> +    struct gbm_device *device;
> +    int fd;
> +};
> +
> +static void Close(struct vlc_egl_display *display)
> +{
> +    struct sys *sys = display->sys;
> +
> +    assert(sys->device);
> +    assert(sys->fd >= 0);
> +
> +    gbm_device_destroy(sys->device);
> +    vlc_close(sys->fd);
> +
> +    free(sys);
> +}
> +
> +static vlc_egl_display_open_fn Open;
> +static int
> +Open(struct vlc_egl_display *display)
> +{
> +    struct sys *sys = display->sys = malloc(sizeof(*sys));
> +    if (!sys)
> +        return VLC_EGENERIC;
> +
> +    const char *extensions = eglQueryString(EGL_NO_DISPLAY,
> EGL_EXTENSIONS); +    if (!extensions)
> +        return VLC_EGENERIC;
> +
> +    if (!vlc_gl_StrHasToken(extensions, "EGL_KHR_platform_gbm"))
> +        return VLC_EGENERIC;
> +
> +    sys->fd = vlc_open("/dev/dri/card0", O_RDWR);

IMU, you're supposed to open render(N+128), not cardN, for head-less 
operations. Also N should probably be configurable.

> +    if (sys->fd < 0)
> +        return VLC_EGENERIC;
> +
> +    sys->device = gbm_create_device(sys->fd);
> +    if (!sys->device)
> +    {
> +        vlc_close(sys->fd);
> +        return VLC_EGENERIC;
> +    }
> +
> +    display->display = eglGetPlatformDisplay(EGL_PLATFORM_GBM_KHR,
> sys->device, +                                             NULL);
> +    if (display->display == EGL_NO_DISPLAY)
> +    {
> +        gbm_device_destroy(sys->device);
> +        vlc_close(sys->fd);
> +        return VLC_EGENERIC;
> +    }
> +
> +    static const struct vlc_egl_display_ops ops = {
> +        .close = Close,
> +    };
> +    display->ops = &ops;
> +
> +    msg_Info(display, "EGL using GBM platform on device fd %d", sys->fd);
> +    return VLC_SUCCESS;
> +}
> +
> +vlc_module_begin()
> +    set_description("EGL GBM display")
> +    set_capability("egl display", 2)
> +    set_callback(Open)
> +    add_shortcut("egl_display_gbm")
> +vlc_module_end()


-- 
雷米‧德尼-库尔蒙
http://www.remlab.net/





More information about the vlc-devel mailing list