Skip to contentSkip to conversation

ui/egl: Reduce required libraries to build with EGL support

PATCH In review OGAWA Hirofumi 2 participants 7 messages Oct 24, 2015 – Oct 28, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ui/egl: Reduce required libraries to build with EGL support

To support EGL (sdl2-gl, gtk-egl, egl-helpers, etc.), we don't need to install "gl" or "glesv" packages. (Those are used only for milkymist-tmu2).

So, this move check from opengl to egl.

---

 configure            |   34 ++++++++++++++++++++++++++++++++--
 include/ui/console.h |    6 +++---
 include/ui/gtk.h     |    4 ++--
 ui/Makefile.objs     |   20 ++++++++++----------
 ui/gtk.c             |    8 ++++----
 ui/sdl2.c            |    8 ++++----
 vl.c                 |    4 ++--
 7 files changed, 57 insertions(+), 27 deletions(-)
configure renamed from configure~separate-egl +32 -2
diff -puN configure~separate-egl configure
@@ -306,6 +306,7 @@ smartcard=""
 libusb=""
 usb_redir=""
 opengl=""
+egl=""
 zlib="yes"
 lzo=""
 snappy=""
@@ -1031,6 +1032,10 @@ for opt do
   ;;
   --enable-opengl) opengl="yes"
   ;;
+  --disable-egl) egl="no"
+  ;;
+  --enable-egl) egl="yes"
+  ;;
   --disable-rbd) rbd="no"
   ;;
   --enable-rbd) rbd="yes"
@@ -3209,7 +3214,7 @@ fi
 libs_softmmu="$libs_softmmu $fdt_libs"
 
 ##########################################
-# opengl probe (for sdl2, milkymist-tmu2)
+# opengl probe (for milkymist-tmu2)
 
 # GLX probe, used by milkymist-tmu2
 # this is temporary, code will be switched to egl mid-term.
@@ -3226,7 +3231,7 @@ else
 fi
 
 if test "$opengl" != "no" ; then
-  opengl_pkgs="gl glesv2 epoxy egl"
+  opengl_pkgs="gl glesv2"
   if $pkg_config $opengl_pkgs x11 && test "$have_glx" = "yes"; then
     opengl_cflags="$($pkg_config --cflags $opengl_pkgs) $x11_cflags"
     opengl_libs="$($pkg_config --libs $opengl_pkgs) $x11_libs"
@@ -3241,6 +3246,24 @@ if test "$opengl" != "no" ; then
   fi
 fi
 
+##########################################
+# egl probe (for sdl2/gtk egl)
+
+if test "$egl" != "no" ; then
+  egl_pkgs="epoxy egl"
+  if $pkg_config $egl_pkgs; then
+    egl_cflags="$($pkg_config --cflags $egl_pkgs)"
+    egl_libs="$($pkg_config --libs $egl_pkgs)"
+    egl=yes
+  else
+    if test "$egl" = "yes" ; then
+      feature_not_found "egl" "Please install egl (mesa) devel pkgs: $egl_pkgs"
+    fi
+    egl_cflags=""
+    egl_libs=""
+    egl=no
+  fi
+fi
 
 ##########################################
 # archipelago probe
@@ -4639,6 +4662,7 @@ echo "smartcard support $smartcard"
 echo "libusb            $libusb"
 echo "usb net redir     $usb_redir"
 echo "OpenGL support    $opengl"
+echo "EGL support       $egl"
 echo "libiscsi support  $libiscsi"
 echo "libnfs support    $libnfs"
 echo "build guest agent $guest_agent"
@@ -5030,6 +5054,12 @@ if test "$opengl" = "yes" ; then
   echo "OPENGL_LIBS=$opengl_libs" >> $config_host_mak
 fi
 
+if test "$egl" = "yes" ; then
+  echo "CONFIG_EGL=y" >> $config_host_mak
+  echo "EGL_CFLAGS=$egl_cflags" >> $config_host_mak
+  echo "EGL_LIBS=$egl_libs" >> $config_host_mak
+fi
+
 if test "$lzo" = "yes" ; then
   echo "CONFIG_LZO=y" >> $config_host_mak
 fi
include/ui/console.h renamed from include/ui/console.h~separate-egl +3 -3
diff -puN include/ui/console.h~separate-egl include/ui/console.h
@@ -9,7 +9,7 @@
 #include "qapi-types.h"
 #include "qapi/error.h"
 
-#ifdef CONFIG_OPENGL
+#ifdef CONFIG_EGL
 # include <epoxy/gl.h>
 #endif
 
@@ -121,7 +121,7 @@ struct DisplaySurface {
     pixman_format_code_t format;
     pixman_image_t *image;
     uint8_t flags;
-#ifdef CONFIG_OPENGL
+#ifdef CONFIG_EGL
     GLenum glformat;
     GLenum gltype;
     GLuint texture;
@@ -335,7 +335,7 @@ DisplaySurface *qemu_console_surface(Qem
 
 /* console-gl.c */
 typedef struct ConsoleGLState ConsoleGLState;
-#ifdef CONFIG_OPENGL
+#ifdef CONFIG_EGL
 ConsoleGLState *console_gl_init_context(void);
 void console_gl_fini_context(ConsoleGLState *gls);
 bool console_gl_check_format(DisplayChangeListener *dcl,
include/ui/gtk.h renamed from include/ui/gtk.h~separate-egl +2 -2
diff -puN include/ui/gtk.h~separate-egl include/ui/gtk.h
@@ -18,7 +18,7 @@
 #include <X11/XKBlib.h>
 #endif
 
-#if defined(CONFIG_OPENGL)
+#if defined(CONFIG_EGL)
 #include "ui/egl-helpers.h"
 #endif
 
@@ -41,7 +41,7 @@ typedef struct VirtualGfxConsole {
     cairo_surface_t *surface;
     double scale_x;
     double scale_y;
-#if defined(CONFIG_OPENGL)
+#if defined(CONFIG_EGL)
     ConsoleGLState *gls;
     EGLContext ectx;
     EGLSurface esurface;
ui/Makefile.objs renamed from ui/Makefile.objs~separate-egl +10 -10
diff -puN ui/Makefile.objs~separate-egl ui/Makefile.objs
@@ -21,13 +21,13 @@ sdl.mo-objs := sdl.o sdl_zoom.o
 endif
 ifeq ($(CONFIG_SDLABI),2.0)
 sdl.mo-objs := sdl2.o sdl2-input.o sdl2-2d.o
-ifeq ($(CONFIG_OPENGL),y)
+ifeq ($(CONFIG_EGL),y)
 sdl.mo-objs += sdl2-gl.o
 endif
 endif
 sdl.mo-cflags := $(SDL_CFLAGS)
 
-ifeq ($(CONFIG_OPENGL),y)
+ifeq ($(CONFIG_EGL),y)
 common-obj-y += shader.o
 common-obj-y += console-gl.o
 common-obj-y += egl-helpers.o
@@ -35,12 +35,12 @@ common-obj-$(CONFIG_GTK) += gtk-egl.o
 endif
 
 gtk.o-cflags := $(GTK_CFLAGS) $(VTE_CFLAGS)
-gtk-egl.o-cflags := $(GTK_CFLAGS) $(VTE_CFLAGS) $(OPENGL_CFLAGS)
-shader.o-cflags += $(OPENGL_CFLAGS)
-console-gl.o-cflags += $(OPENGL_CFLAGS)
-egl-helpers.o-cflags += $(OPENGL_CFLAGS)
+gtk-egl.o-cflags := $(GTK_CFLAGS) $(VTE_CFLAGS) $(EGL_CFLAGS)
+shader.o-cflags += $(EGL_CFLAGS)
+console-gl.o-cflags += $(EGL_CFLAGS)
+egl-helpers.o-cflags += $(EGL_CFLAGS)
 
-gtk-egl.o-libs += $(OPENGL_LIBS)
-shader.o-libs += $(OPENGL_LIBS)
-console-gl.o-libs += $(OPENGL_LIBS)
-egl-helpers.o-libs += $(OPENGL_LIBS)
+gtk-egl.o-libs += $(EGL_LIBS)
+shader.o-libs += $(EGL_LIBS)
+console-gl.o-libs += $(EGL_LIBS)
+egl-helpers.o-libs += $(EGL_LIBS)
ui/gtk.c renamed from ui/gtk.c~separate-egl +4 -4
diff -puN ui/gtk.c~separate-egl ui/gtk.c
@@ -603,7 +603,7 @@ static const DisplayChangeListenerOps dc
 };
 
 
-#if defined(CONFIG_OPENGL)
+#if defined(CONFIG_EGL)
 
 /** DisplayState Callbacks (opengl version) **/
 
@@ -675,7 +675,7 @@ static gboolean gd_draw_event(GtkWidget
     int ww, wh;
     int fbw, fbh;
 
-#if defined(CONFIG_OPENGL)
+#if defined(CONFIG_EGL)
     if (vc->gfx.gls) {
         gd_egl_draw(vc);
         return TRUE;
@@ -1754,7 +1754,7 @@ static GSList *gd_vc_gfx_init(GtkDisplay
     gtk_notebook_append_page(GTK_NOTEBOOK(s->notebook),
                              vc->tab_item, gtk_label_new(vc->label));
 
-#if defined(CONFIG_OPENGL)
+#if defined(CONFIG_EGL)
     if (display_opengl) {
         /*
          * gtk_widget_set_double_buffered() was deprecated in 3.14.
@@ -2058,7 +2058,7 @@ void early_gtk_display_init(int opengl)
     case 0:  /* off */
         break;
     case 1: /* on */
-#if defined(CONFIG_OPENGL)
+#if defined(CONFIG_EGL)
         gtk_egl_init();
 #endif
         break;
ui/sdl2.c renamed from ui/sdl2.c~separate-egl +4 -4
diff -puN ui/sdl2.c~separate-egl ui/sdl2.c
@@ -118,7 +118,7 @@ void sdl2_window_resize(struct sdl2_cons
 static void sdl2_redraw(struct sdl2_console *scon)
 {
     if (scon->opengl) {
-#ifdef CONFIG_OPENGL
+#ifdef CONFIG_EGL
         sdl2_gl_redraw(scon);
 #endif
     } else {
@@ -691,7 +691,7 @@ static const DisplayChangeListenerOps dc
     .dpy_cursor_define    = sdl_mouse_define,
 };
 
-#ifdef CONFIG_OPENGL
+#ifdef CONFIG_EGL
 static const DisplayChangeListenerOps dcl_gl_ops = {
     .dpy_name                = "sdl2-gl",
     .dpy_gfx_update          = sdl2_gl_update,
@@ -710,7 +710,7 @@ void sdl_display_early_init(int opengl)
     case 0:  /* off */
         break;
     case 1: /* on */
-#ifdef CONFIG_OPENGL
+#ifdef CONFIG_EGL
         display_opengl = 1;
 #endif
         break;
@@ -766,7 +766,7 @@ void sdl_display_init(DisplayState *ds,
             sdl2_console[i].hidden = true;
         }
         sdl2_console[i].idx = i;
-#ifdef CONFIG_OPENGL
+#ifdef CONFIG_EGL
         sdl2_console[i].opengl = display_opengl;
         sdl2_console[i].dcl.ops = display_opengl ? &dcl_gl_ops : &dcl_2d_ops;
 #else
vl.c renamed from vl.c~separate-egl +2 -2
diff -puN vl.c~separate-egl vl.c
@@ -4221,10 +4221,10 @@ int main(int argc, char **argv, char **e
     }
 #endif
     if (request_opengl == 1 && display_opengl == 0) {
-#if defined(CONFIG_OPENGL)
+#if defined(CONFIG_EGL)
         fprintf(stderr, "OpenGL is not supported by the display.\n");
 #else
-        fprintf(stderr, "QEMU was built without opengl support.\n");
+        fprintf(stderr, "QEMU was built without egl support.\n");
 #endif
         exit(1);
     }

_

#1 lore raw
Quoted 2 lines · OGAWA Hirofumi

To support EGL (sdl2-gl, gtk-egl, egl-helpers, etc.), we don't need to install "gl" or "glesv" packages. (Those are used only for milkymist-tmu2).

They are needed and used. Maybe it works if you don't explicitly link them because epoxy brings them in indirectly then.

cheers,
Gerd

#2 lore raw
Quoted 6 lines · Gerd Hoffmann
Quoted 2 lines · OGAWA Hirofumi

To support EGL (sdl2-gl, gtk-egl, egl-helpers, etc.), we don't need to install "gl" or "glesv" packages. (Those are used only for milkymist-tmu2).

They are needed and used. Maybe it works if you don't explicitly link them because epoxy brings them in indirectly then.

Hm, I meant, we don't need to explicitly install those development packages. I.e. epoxy handling those dynamically.

With epoxy, it removes dependency of development stuff (e.g. headers, (no versioned) *.so), so no need check those by pkg-config? IOW, need runtime stuff only.

Thanks.

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#3 lore raw
Quoted 11 lines · OGAWA Hirofumi
Quoted 6 lines · Gerd Hoffmann
Quoted 2 lines · OGAWA Hirofumi

To support EGL (sdl2-gl, gtk-egl, egl-helpers, etc.), we don't need to install "gl" or "glesv" packages. (Those are used only for milkymist-tmu2).

They are needed and used. Maybe it works if you don't explicitly link them because epoxy brings them in indirectly then.

Hm, I meant, we don't need to explicitly install those development packages. I.e. epoxy handling those dynamically.

Ah, I see. Can we just move over tmu2 to use epoxy too, then drop the deps handled by epoxy? So we don't need a new CONFIG_EGL option ...

Ideally tmu2 should also be moved from talking to glx directly to use the (egl-based) qemu opengl interfaces. That'll be a bit more work though as tmu2 needs be ported to the modern opengl desktop interfaces then ...

cheers,
Gerd

#4 lore raw
Quoted 7 lines · Gerd Hoffmann
Quoted 6 lines · OGAWA Hirofumi
Quoted 4 lines · Gerd Hoffmann
Quoted 2 lines · OGAWA Hirofumi

To support EGL (sdl2-gl, gtk-egl, egl-helpers, etc.), we don't need to install "gl" or "glesv" packages. (Those are used only for milkymist-tmu2).

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

They are needed and used. Maybe it works if you don't explicitly link them because epoxy brings them in indirectly then.

Hm, I meant, we don't need to explicitly install those development packages. I.e. epoxy handling those dynamically.

Ah, I see. Can we just move over tmu2 to use epoxy too, then drop the deps handled by epoxy? So we don't need a new CONFIG_EGL option ...

Sounds good.

Quoted 4 lines

Ideally tmu2 should also be moved from talking to glx directly to use the (egl-based) qemu opengl interfaces. That'll be a bit more work though as tmu2 needs be ported to the modern opengl desktop interfaces then ...

Sure. But it was hard to do for right now, so will send just epoxy stuff.

Thanks.

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#5 lore raw

PATCH v2 1/1 ui/opengl: Reduce build required libraries for opengl

We now use epoxy to load opengl libraries. This means we don't need to link opengl libraries directly if interfaces handled by epoxy. With this, we just need epoxy headers and epoxy's *.so to build.

Tested with epoxy-1.3.1.

- sdl2/gtk/console egl stuff doesn't require other than epoxy
- milkymist-tmu2 glx stuff doesn't require other than epoxy

(lm32 test is limited, because can't find mmone-bios.bin, so just test to load libGL with "./lm32-softmmu/qemu-system-lm32 -M milkymist,accel=qtest")

---

 configure                   |   20 +++-----------------
 hw/display/milkymist-tmu2.c |    4 ++--
 hw/lm32/milkymist-hw.h      |    3 ++-
 3 files changed, 7 insertions(+), 20 deletions(-)
configure renamed from configure~use-epoxy +3 -17
diff -puN configure~use-epoxy configure
@@ -3149,25 +3149,11 @@ fi
 libs_softmmu="$libs_softmmu $fdt_libs"
 
 ##########################################
-# opengl probe (for sdl2, milkymist-tmu2)
-
-# GLX probe, used by milkymist-tmu2
-# this is temporary, code will be switched to egl mid-term.
-cat > $TMPC << EOF
-#include <X11/Xlib.h>
-#include <GL/gl.h>
-#include <GL/glx.h>
-int main(void) { glBegin(0); glXQueryVersion(0,0,0); return 0; }
-EOF
-if compile_prog "" "-lGL -lX11" ; then
-  have_glx=yes
-else
-  have_glx=no
-fi
+# opengl probe (for sdl2, gtk, milkymist-tmu2)
 
 if test "$opengl" != "no" ; then
-  opengl_pkgs="gl glesv2 epoxy egl"
-  if $pkg_config $opengl_pkgs x11 && test "$have_glx" = "yes"; then
+  opengl_pkgs="epoxy"
+  if $pkg_config $opengl_pkgs x11; then
     opengl_cflags="$($pkg_config --cflags $opengl_pkgs) $x11_cflags"
     opengl_libs="$($pkg_config --libs $opengl_pkgs) $x11_libs"
     opengl=yes
hw/lm32/milkymist-hw.h renamed from hw/lm32/milkymist-hw.h~use-epoxy +2 -1
diff -puN hw/lm32/milkymist-hw.h~use-epoxy hw/lm32/milkymist-hw.h
@@ -88,7 +88,8 @@ static inline DeviceState *milkymist_pfp
 
 #ifdef CONFIG_OPENGL
 #include <X11/Xlib.h>
-#include <GL/glx.h>
+#include <epoxy/gl.h>
+#include <epoxy/glx.h>
 static const int glx_fbconfig_attr[] = {
     GLX_GREEN_SIZE, 5,
     GLX_GREEN_SIZE, 6,
hw/display/milkymist-tmu2.c renamed from hw/display/milkymist-tmu2.c~use-epoxy +2 -2
diff -puN hw/display/milkymist-tmu2.c~use-epoxy hw/display/milkymist-tmu2.c
@@ -30,8 +30,8 @@
 #include "qemu/error-report.h"
 
 #include <X11/Xlib.h>
-#include <GL/gl.h>
-#include <GL/glx.h>
+#include <epoxy/gl.h>
+#include <epoxy/glx.h>
 
 enum {
     R_CTL = 0,

_

#6 lore raw

Re: [Qemu-devel] [PATCH v2] ui/opengl: Reduce build required libraries for opengl

Quoted 11 lines · OGAWA Hirofumi

We now use epoxy to load opengl libraries. This means we don't need to link opengl libraries directly if interfaces handled by epoxy. With this, we just need epoxy headers and epoxy's *.so to build.

Tested with epoxy-1.3.1.

- sdl2/gtk/console egl stuff doesn't require other than epoxy
- milkymist-tmu2 glx stuff doesn't require other than epoxy

(lm32 test is limited, because can't find mmone-bios.bin, so just test to load libGL with "./lm32-softmmu/qemu-system-lm32 -M milkymist,accel=qtest")

I've tested it, works. Patch queued up.

thanks,
Gerd