浏览代码

configure: Improve OpenGL dependency detections

This has the following visible changes:

- GBM is required only for OpenGL dma-buf.
- X11 is explicitly required by gtk-egl.
- EGL is now mandatory for the OpenGL displays.

The last one needs some detailed description. Before this change,
EGL was tested only for OpenGL dma-buf with the check of
EGL_MESA_image_dma_buf_export. However, all of the OpenGL
displays depend on EGL and EGL_MESA_image_dma_buf_export is always
defined by epoxy's EGL interface.
Therefore, it makes more sense to always check the presence of EGL
and say the OpenGL displays are available along with OpenGL dma-buf
if it is present.

Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Message-Id: <20210223060307.87736-1-akihiko.odaki@gmail.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Akihiko Odaki 4 年之前
父节点
当前提交
bc6a3565c8
共有 10 个文件被更改,包括 56 次插入35 次删除
  1. 15 22
      configure
  2. 2 1
      docs/interop/vhost-user.json
  3. 8 1
      include/ui/egl-helpers.h
  4. 1 1
      include/ui/spice-display.h
  5. 1 1
      meson.build
  6. 6 2
      ui/egl-helpers.c
  7. 3 3
      ui/gtk-egl.c
  8. 1 1
      ui/gtk-gl-area.c
  9. 14 0
      ui/gtk.c
  10. 5 3
      ui/meson.build

+ 15 - 22
configure

@@ -394,7 +394,6 @@ u2f="auto"
 libusb="$default_feature"
 libusb="$default_feature"
 usb_redir="$default_feature"
 usb_redir="$default_feature"
 opengl="$default_feature"
 opengl="$default_feature"
-opengl_dmabuf="no"
 cpuid_h="no"
 cpuid_h="no"
 avx2_opt="$default_feature"
 avx2_opt="$default_feature"
 capstone="auto"
 capstone="auto"
@@ -3607,14 +3606,24 @@ if $pkg_config gbm; then
 fi
 fi
 
 
 if test "$opengl" != "no" ; then
 if test "$opengl" != "no" ; then
-  opengl_pkgs="epoxy gbm"
-  if $pkg_config $opengl_pkgs; then
-    opengl_cflags="$($pkg_config --cflags $opengl_pkgs)"
-    opengl_libs="$($pkg_config --libs $opengl_pkgs)"
+  epoxy=no
+  if $pkg_config epoxy; then
+    cat > $TMPC << EOF
+#include <epoxy/egl.h>
+int main(void) { return 0; }
+EOF
+    if compile_prog "" "" ; then
+      epoxy=yes
+    fi
+  fi
+
+  if test "$epoxy" = "yes" ; then
+    opengl_cflags="$($pkg_config --cflags epoxy)"
+    opengl_libs="$($pkg_config --libs epoxy)"
     opengl=yes
     opengl=yes
   else
   else
     if test "$opengl" = "yes" ; then
     if test "$opengl" = "yes" ; then
-      feature_not_found "opengl" "Please install opengl (mesa) devel pkgs: $opengl_pkgs"
+      feature_not_found "opengl" "Please install epoxy with EGL"
     fi
     fi
     opengl_cflags=""
     opengl_cflags=""
     opengl_libs=""
     opengl_libs=""
@@ -3622,19 +3631,6 @@ if test "$opengl" != "no" ; then
   fi
   fi
 fi
 fi
 
 
-if test "$opengl" = "yes"; then
-  cat > $TMPC << EOF
-#include <epoxy/egl.h>
-#ifndef EGL_MESA_image_dma_buf_export
-# error mesa/epoxy lacks support for dmabufs (mesa 10.6+)
-#endif
-int main(void) { return 0; }
-EOF
-  if compile_prog "" "" ; then
-    opengl_dmabuf=yes
-  fi
-fi
-
 ##########################################
 ##########################################
 # libxml2 probe
 # libxml2 probe
 if test "$libxml2" != "no" ; then
 if test "$libxml2" != "no" ; then
@@ -5837,9 +5833,6 @@ if test "$opengl" = "yes" ; then
   echo "CONFIG_OPENGL=y" >> $config_host_mak
   echo "CONFIG_OPENGL=y" >> $config_host_mak
   echo "OPENGL_CFLAGS=$opengl_cflags" >> $config_host_mak
   echo "OPENGL_CFLAGS=$opengl_cflags" >> $config_host_mak
   echo "OPENGL_LIBS=$opengl_libs" >> $config_host_mak
   echo "OPENGL_LIBS=$opengl_libs" >> $config_host_mak
-  if test "$opengl_dmabuf" = "yes" ; then
-    echo "CONFIG_OPENGL_DMABUF=y" >> $config_host_mak
-  fi
 fi
 fi
 
 
 if test "$gbm" = "yes" ; then
 if test "$gbm" = "yes" ; then

+ 2 - 1
docs/interop/vhost-user.json

@@ -250,7 +250,8 @@
 #   "type": "gpu",
 #   "type": "gpu",
 #   "binary": "/usr/libexec/qemu/vhost-user-gpu",
 #   "binary": "/usr/libexec/qemu/vhost-user-gpu",
 #   "tags": [
 #   "tags": [
-#     "CONFIG_OPENGL_DMABUF=y"
+#     "CONFIG_OPENGL=y",
+#     "CONFIG_GBM=y"
 #   ]
 #   ]
 # }
 # }
 #
 #

+ 8 - 1
include/ui/egl-helpers.h

@@ -3,7 +3,9 @@
 
 
 #include <epoxy/gl.h>
 #include <epoxy/gl.h>
 #include <epoxy/egl.h>
 #include <epoxy/egl.h>
+#ifdef CONFIG_GBM
 #include <gbm.h>
 #include <gbm.h>
+#endif
 #include "ui/console.h"
 #include "ui/console.h"
 #include "ui/shader.h"
 #include "ui/shader.h"
 
 
@@ -31,7 +33,7 @@ void egl_texture_blit(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip);
 void egl_texture_blend(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip,
 void egl_texture_blend(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip,
                        int x, int y, double scale_x, double scale_y);
                        int x, int y, double scale_x, double scale_y);
 
 
-#ifdef CONFIG_OPENGL_DMABUF
+#ifdef CONFIG_GBM
 
 
 extern int qemu_egl_rn_fd;
 extern int qemu_egl_rn_fd;
 extern struct gbm_device *qemu_egl_rn_gbm_dev;
 extern struct gbm_device *qemu_egl_rn_gbm_dev;
@@ -48,8 +50,13 @@ void egl_dmabuf_release_texture(QemuDmaBuf *dmabuf);
 
 
 EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, EGLNativeWindowType win);
 EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, EGLNativeWindowType win);
 
 
+#if defined(CONFIG_X11) || defined(CONFIG_GBM)
+
 int qemu_egl_init_dpy_x11(EGLNativeDisplayType dpy, DisplayGLMode mode);
 int qemu_egl_init_dpy_x11(EGLNativeDisplayType dpy, DisplayGLMode mode);
 int qemu_egl_init_dpy_mesa(EGLNativeDisplayType dpy, DisplayGLMode mode);
 int qemu_egl_init_dpy_mesa(EGLNativeDisplayType dpy, DisplayGLMode mode);
+
+#endif
+
 EGLContext qemu_egl_init_ctx(void);
 EGLContext qemu_egl_init_ctx(void);
 bool qemu_egl_has_dmabuf(void);
 bool qemu_egl_has_dmabuf(void);
 
 

+ 1 - 1
include/ui/spice-display.h

@@ -27,7 +27,7 @@
 #include "ui/qemu-pixman.h"
 #include "ui/qemu-pixman.h"
 #include "ui/console.h"
 #include "ui/console.h"
 
 
-#if defined(CONFIG_OPENGL_DMABUF)
+#if defined(CONFIG_OPENGL) && defined(CONFIG_GBM)
 # if SPICE_SERVER_VERSION >= 0x000d01 /* release 0.13.1 */
 # if SPICE_SERVER_VERSION >= 0x000d01 /* release 0.13.1 */
 #  define HAVE_SPICE_GL 1
 #  define HAVE_SPICE_GL 1
 #  include "ui/egl-helpers.h"
 #  include "ui/egl-helpers.h"

+ 1 - 1
meson.build

@@ -2648,7 +2648,7 @@ summary_info += {'U2F support':       u2f.found()}
 summary_info += {'libusb':            config_host.has_key('CONFIG_USB_LIBUSB')}
 summary_info += {'libusb':            config_host.has_key('CONFIG_USB_LIBUSB')}
 summary_info += {'usb net redir':     config_host.has_key('CONFIG_USB_REDIR')}
 summary_info += {'usb net redir':     config_host.has_key('CONFIG_USB_REDIR')}
 summary_info += {'OpenGL support':    config_host.has_key('CONFIG_OPENGL')}
 summary_info += {'OpenGL support':    config_host.has_key('CONFIG_OPENGL')}
-summary_info += {'OpenGL dmabufs':    config_host.has_key('CONFIG_OPENGL_DMABUF')}
+summary_info += {'GBM':               config_host.has_key('CONFIG_GBM')}
 summary_info += {'libiscsi support':  libiscsi.found()}
 summary_info += {'libiscsi support':  libiscsi.found()}
 summary_info += {'libnfs support':    libnfs.found()}
 summary_info += {'libnfs support':    libnfs.found()}
 if targetos == 'windows'
 if targetos == 'windows'

+ 6 - 2
ui/egl-helpers.c

@@ -140,7 +140,7 @@ void egl_texture_blend(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip,
 
 
 /* ---------------------------------------------------------------------- */
 /* ---------------------------------------------------------------------- */
 
 
-#ifdef CONFIG_OPENGL_DMABUF
+#ifdef CONFIG_GBM
 
 
 int qemu_egl_rn_fd;
 int qemu_egl_rn_fd;
 struct gbm_device *qemu_egl_rn_gbm_dev;
 struct gbm_device *qemu_egl_rn_gbm_dev;
@@ -287,7 +287,7 @@ void egl_dmabuf_release_texture(QemuDmaBuf *dmabuf)
     dmabuf->texture = 0;
     dmabuf->texture = 0;
 }
 }
 
 
-#endif /* CONFIG_OPENGL_DMABUF */
+#endif /* CONFIG_GBM */
 
 
 /* ---------------------------------------------------------------------- */
 /* ---------------------------------------------------------------------- */
 
 
@@ -315,6 +315,8 @@ EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, EGLNativeWindowType win)
 
 
 /* ---------------------------------------------------------------------- */
 /* ---------------------------------------------------------------------- */
 
 
+#if defined(CONFIG_X11) || defined(CONFIG_GBM)
+
 /*
 /*
  * Taken from glamor_egl.h from the Xorg xserver, which is MIT licensed
  * Taken from glamor_egl.h from the Xorg xserver, which is MIT licensed
  *
  *
@@ -441,6 +443,8 @@ int qemu_egl_init_dpy_mesa(EGLNativeDisplayType dpy, DisplayGLMode mode)
 #endif
 #endif
 }
 }
 
 
+#endif
+
 bool qemu_egl_has_dmabuf(void)
 bool qemu_egl_has_dmabuf(void)
 {
 {
     if (qemu_egl_display == EGL_NO_DISPLAY) {
     if (qemu_egl_display == EGL_NO_DISPLAY) {

+ 3 - 3
ui/gtk-egl.c

@@ -208,7 +208,7 @@ void gd_egl_scanout_texture(DisplayChangeListener *dcl,
 void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl,
 void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl,
                            QemuDmaBuf *dmabuf)
                            QemuDmaBuf *dmabuf)
 {
 {
-#ifdef CONFIG_OPENGL_DMABUF
+#ifdef CONFIG_GBM
     egl_dmabuf_import_texture(dmabuf);
     egl_dmabuf_import_texture(dmabuf);
     if (!dmabuf->texture) {
     if (!dmabuf->texture) {
         return;
         return;
@@ -224,7 +224,7 @@ void gd_egl_cursor_dmabuf(DisplayChangeListener *dcl,
                           QemuDmaBuf *dmabuf, bool have_hot,
                           QemuDmaBuf *dmabuf, bool have_hot,
                           uint32_t hot_x, uint32_t hot_y)
                           uint32_t hot_x, uint32_t hot_y)
 {
 {
-#ifdef CONFIG_OPENGL_DMABUF
+#ifdef CONFIG_GBM
     VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
     VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
 
 
     if (dmabuf) {
     if (dmabuf) {
@@ -252,7 +252,7 @@ void gd_egl_cursor_position(DisplayChangeListener *dcl,
 void gd_egl_release_dmabuf(DisplayChangeListener *dcl,
 void gd_egl_release_dmabuf(DisplayChangeListener *dcl,
                            QemuDmaBuf *dmabuf)
                            QemuDmaBuf *dmabuf)
 {
 {
-#ifdef CONFIG_OPENGL_DMABUF
+#ifdef CONFIG_GBM
     egl_dmabuf_release_texture(dmabuf);
     egl_dmabuf_release_texture(dmabuf);
 #endif
 #endif
 }
 }

+ 1 - 1
ui/gtk-gl-area.c

@@ -219,7 +219,7 @@ void gd_gl_area_scanout_flush(DisplayChangeListener *dcl,
 void gd_gl_area_scanout_dmabuf(DisplayChangeListener *dcl,
 void gd_gl_area_scanout_dmabuf(DisplayChangeListener *dcl,
                                QemuDmaBuf *dmabuf)
                                QemuDmaBuf *dmabuf)
 {
 {
-#ifdef CONFIG_OPENGL_DMABUF
+#ifdef CONFIG_GBM
     VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
     VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
 
 
     gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
     gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));

+ 14 - 0
ui/gtk.c

@@ -657,6 +657,8 @@ static const DisplayChangeListenerOps dcl_gl_area_ops = {
     .dpy_has_dmabuf          = gd_has_dmabuf,
     .dpy_has_dmabuf          = gd_has_dmabuf,
 };
 };
 
 
+#ifdef CONFIG_X11
+
 static const DisplayChangeListenerOps dcl_egl_ops = {
 static const DisplayChangeListenerOps dcl_egl_ops = {
     .dpy_name             = "gtk-egl",
     .dpy_name             = "gtk-egl",
     .dpy_gfx_update       = gd_egl_update,
     .dpy_gfx_update       = gd_egl_update,
@@ -679,6 +681,8 @@ static const DisplayChangeListenerOps dcl_egl_ops = {
     .dpy_has_dmabuf          = gd_has_dmabuf,
     .dpy_has_dmabuf          = gd_has_dmabuf,
 };
 };
 
 
+#endif
+
 #endif /* CONFIG_OPENGL */
 #endif /* CONFIG_OPENGL */
 
 
 /** QEMU Events **/
 /** QEMU Events **/
@@ -797,8 +801,12 @@ static gboolean gd_draw_event(GtkWidget *widget, cairo_t *cr, void *opaque)
             /* invoke render callback please */
             /* invoke render callback please */
             return FALSE;
             return FALSE;
         } else {
         } else {
+#ifdef CONFIG_X11
             gd_egl_draw(vc);
             gd_egl_draw(vc);
             return TRUE;
             return TRUE;
+#else
+            abort();
+#endif
         }
         }
     }
     }
 #endif
 #endif
@@ -2031,6 +2039,7 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc,
                              G_CALLBACK(gl_area_realize), vc);
                              G_CALLBACK(gl_area_realize), vc);
             vc->gfx.dcl.ops = &dcl_gl_area_ops;
             vc->gfx.dcl.ops = &dcl_gl_area_ops;
         } else {
         } else {
+#ifdef CONFIG_X11
             vc->gfx.drawing_area = gtk_drawing_area_new();
             vc->gfx.drawing_area = gtk_drawing_area_new();
             /*
             /*
              * gtk_widget_set_double_buffered() was deprecated in 3.14.
              * gtk_widget_set_double_buffered() was deprecated in 3.14.
@@ -2044,6 +2053,9 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc,
 #pragma GCC diagnostic pop
 #pragma GCC diagnostic pop
             vc->gfx.dcl.ops = &dcl_egl_ops;
             vc->gfx.dcl.ops = &dcl_egl_ops;
             vc->gfx.has_dmabuf = qemu_egl_has_dmabuf();
             vc->gfx.has_dmabuf = qemu_egl_has_dmabuf();
+#else
+            abort();
+#endif
         }
         }
     } else
     } else
 #endif
 #endif
@@ -2354,8 +2366,10 @@ static void early_gtk_display_init(DisplayOptions *opts)
         } else
         } else
 #endif
 #endif
         {
         {
+#ifdef CONFIG_X11
             DisplayGLMode mode = opts->has_gl ? opts->gl : DISPLAYGL_MODE_ON;
             DisplayGLMode mode = opts->has_gl ? opts->gl : DISPLAYGL_MODE_ON;
             gtk_egl_init(mode);
             gtk_egl_init(mode);
+#endif
         }
         }
 #endif
 #endif
     }
     }

+ 5 - 3
ui/meson.build

@@ -45,14 +45,15 @@ endif
 
 
 if config_host.has_key('CONFIG_OPENGL')
 if config_host.has_key('CONFIG_OPENGL')
   opengl_ss = ss.source_set()
   opengl_ss = ss.source_set()
+  opengl_ss.add(gbm)
   opengl_ss.add(when: [opengl, pixman, 'CONFIG_OPENGL'],
   opengl_ss.add(when: [opengl, pixman, 'CONFIG_OPENGL'],
                if_true: files('shader.c', 'console-gl.c', 'egl-helpers.c', 'egl-context.c'))
                if_true: files('shader.c', 'console-gl.c', 'egl-helpers.c', 'egl-context.c'))
   ui_modules += {'opengl' : opengl_ss}
   ui_modules += {'opengl' : opengl_ss}
 endif
 endif
 
 
-if config_host.has_key('CONFIG_OPENGL_DMABUF')
+if config_host.has_key('CONFIG_OPENGL') and gbm.found()
   egl_headless_ss = ss.source_set()
   egl_headless_ss = ss.source_set()
-  egl_headless_ss.add(when: [opengl, pixman, 'CONFIG_OPENGL_DMABUF'],
+  egl_headless_ss.add(when: [opengl, gbm, pixman, 'CONFIG_OPENGL'],
                       if_true: files('egl-headless.c'))
                       if_true: files('egl-headless.c'))
   ui_modules += {'egl-headless' : egl_headless_ss}
   ui_modules += {'egl-headless' : egl_headless_ss}
 endif
 endif
@@ -63,7 +64,8 @@ if gtk.found()
   gtk_ss = ss.source_set()
   gtk_ss = ss.source_set()
   gtk_ss.add(gtk, vte, pixman, files('gtk.c'))
   gtk_ss.add(gtk, vte, pixman, files('gtk.c'))
   gtk_ss.add(when: x11, if_true: files('x_keymap.c'))
   gtk_ss.add(when: x11, if_true: files('x_keymap.c'))
-  gtk_ss.add(when: [opengl, 'CONFIG_OPENGL'], if_true: files('gtk-egl.c', 'gtk-gl-area.c'))
+  gtk_ss.add(when: [opengl, 'CONFIG_OPENGL'], if_true: files('gtk-gl-area.c'))
+  gtk_ss.add(when: [x11, opengl, 'CONFIG_OPENGL'], if_true: files('gtk-egl.c'))
   ui_modules += {'gtk' : gtk_ss}
   ui_modules += {'gtk' : gtk_ss}
 endif
 endif