Skip to contentSkip to conversation

gtk: add opengl support

PATCH Superseded Gerd Hoffmann 2 participants 12 messages May 19, 2015 – May 20, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover gtk: add opengl support

Hi,

opengl support continued. This series brings some little fixups, adds egl helper functions and implements opengl support for the gtk ui using that.

please review,
Gerd

Gerd Hoffmann (4):
ui: use libexpoxy
ui: shader.h protect against double inclusion
ui: add egl-helpers
gtk: add opengl support, using egl

 configure                |   2 +-
 include/ui/console.h     |   5 +-
 include/ui/egl-helpers.h |  16 ++++++
 include/ui/gtk.h         |  23 ++++++++
 include/ui/shader.h      |  10 ++--
 ui/Makefile.objs         |   6 ++
 ui/egl-helpers.c         | 143 +++++++++++++++++++++++++++++++++++++++++++++++
 ui/gtk-egl.c             | 141 ++++++++++++++++++++++++++++++++++++++++++++++
 ui/gtk.c                 |  77 ++++++++++++++++++++-----
 vl.c                     |  11 +++-
 10 files changed, 410 insertions(+), 24 deletions(-)
 create mode 100644 include/ui/egl-helpers.h
 create mode 100644 ui/egl-helpers.c
 create mode 100644 ui/gtk-egl.c
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/4 ui: use libexpoxy

libepoxy does the opengl extension handling for us.

It also is helpful for trouble-shooting as it prints nice error messages instead of silently failing or segfaulting in case we do something wrong, like using gl commands not supported by the current context.

---
 configure            | 2 +-
 include/ui/console.h | 3 +--
 include/ui/shader.h  | 5 +----
 3 files changed, 3 insertions(+), 7 deletions(-)
configure +1 -1
index 1f0f485..df1048a 100755
@@ -3153,7 +3153,7 @@ else
 fi
 
 if test "$opengl" != "no" ; then
-  opengl_pkgs="gl glesv2"
+  opengl_pkgs="gl glesv2 epoxy"
   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"
include/ui/console.h +1 -2
index e8b3a9e..383dec2 100644
@@ -10,8 +10,7 @@
 #include "qapi/error.h"
 
 #ifdef CONFIG_OPENGL
-# include <GLES2/gl2.h>
-# include <GLES2/gl2ext.h>
+# include <epoxy/gl.h>
 #endif
 
 /* keyboard/mouse support */
include/ui/shader.h +1 -4
index 1ff926c..992cde6 100644
@@ -1,7 +1,4 @@
-#ifdef CONFIG_OPENGL
-# include <GLES2/gl2.h>
-# include <GLES2/gl2ext.h>
-#endif
+#include <epoxy/gl.h>
 
 void qemu_gl_run_texture_blit(GLint texture_blit_prog);
 
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/4
#2 lore raw

Re: [Qemu-devel] [PATCH 1/4] ui: use libexpoxy

Quoted 18 lines · Gerd Hoffmann

libepoxy does the opengl extension handling for us.

It also is helpful for trouble-shooting as it prints nice error messages instead of silently failing or segfaulting in case we do something wrong, like using gl commands not supported by the current context.

---
  configure            | 2 +-
  include/ui/console.h | 3 +--
  include/ui/shader.h  | 5 +----
  3 files changed, 3 insertions(+), 7 deletions(-)
configure +0 -0
index 1f0f485..df1048a 100755

configure else · line 3159

Quoted 8 lines
configure +1 -1
@@ -3153,7 +3153,7 @@ else
  fi
 
  if test "$opengl" != "no" ; then
-  opengl_pkgs="gl glesv2"
+  opengl_pkgs="gl glesv2 epoxy"
    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"

If the package isn't found, the remedy message ("Install GL devel (e.g. MESA)") isn't too helpful now .

Whether you change that or not:

Quoted 26 lines
include/ui/console.h +1 -2
index e8b3a9e..383dec2 100644
@@ -10,8 +10,7 @@
  #include "qapi/error.h"
 
  #ifdef CONFIG_OPENGL
-# include <GLES2/gl2.h>
-# include <GLES2/gl2ext.h>
+# include <epoxy/gl.h>
  #endif
 
  /* keyboard/mouse support */
include/ui/shader.h +1 -4
index 1ff926c..992cde6 100644
@@ -1,7 +1,4 @@
-#ifdef CONFIG_OPENGL
-# include <GLES2/gl2.h>
-# include <GLES2/gl2ext.h>
-#endif
+#include <epoxy/gl.h>
 
  void qemu_gl_run_texture_blit(GLint texture_blit_prog);
#3 lore raw

PATCH 2/4 ui: shader.h protect against double inclusion

In reply to Gerd Hoffmann
---
 include/ui/shader.h | 5 +++++
 1 file changed, 5 insertions(+)
include/ui/shader.h +5 -0
index 992cde6..8509596 100644
@@ -1,3 +1,6 @@
+#ifndef QEMU_SHADER_H
+#define QEMU_SHADER_H
+
 #include <epoxy/gl.h>
 
 void qemu_gl_run_texture_blit(GLint texture_blit_prog);
@@ -6,3 +9,5 @@ GLuint qemu_gl_create_compile_shader(GLenum type, const GLchar *src);
 GLuint qemu_gl_create_link_program(GLuint vert, GLuint frag);
 GLuint qemu_gl_create_compile_link_program(const GLchar *vert_src,
                                            const GLchar *frag_src);
+
+#endif /* QEMU_SHADER_H */
Signature · 1 line
1.8.3.1
#5 lore raw

PATCH 3/4 ui: add egl-helpers

In reply to Gerd Hoffmann

Add helper functions to initialize OpenGL using egl.

---
 configure                |   2 +-
 include/ui/egl-helpers.h |  16 ++++++
 ui/Makefile.objs         |   3 +
 ui/egl-helpers.c         | 143 +++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 163 insertions(+), 1 deletion(-)
 create mode 100644 include/ui/egl-helpers.h
 create mode 100644 ui/egl-helpers.c
configure +1 -1
index df1048a..e0e6b54 100755
@@ -3153,7 +3153,7 @@ else
 fi
 
 if test "$opengl" != "no" ; then
-  opengl_pkgs="gl glesv2 epoxy"
+  opengl_pkgs="gl glesv2 epoxy egl"
   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"
include/ui/egl-helpers.h new file +16 -0
new file mode 100644
index 0000000..5ad5dc3
@@ -0,0 +1,16 @@
+#ifndef EGL_HELPERS_H
+#define EGL_HELPERS_H
+
+#include <epoxy/gl.h>
+#include <epoxy/egl.h>
+
+extern EGLDisplay *qemu_egl_display;
+extern EGLConfig qemu_egl_config;
+
+EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, Window win);
+
+int qemu_egl_init_dpy(EGLNativeDisplayType dpy, bool gles, bool debug);
+EGLContext qemu_egl_init_ctx(void);
+bool qemu_egl_has_ext(const char *haystack, const char *needle);
+
+#endif /* EGL_HELPERS_H */
ui/Makefile.objs +3 -0
index 029a42a..5c46870 100644
@@ -30,11 +30,14 @@ sdl.mo-cflags := $(SDL_CFLAGS)
 ifeq ($(CONFIG_OPENGL),y)
 common-obj-y += shader.o
 common-obj-y += console-gl.o
+common-obj-y += egl-helpers.o
 endif
 
 gtk.o-cflags := $(GTK_CFLAGS) $(VTE_CFLAGS)
 shader.o-cflags += $(OPENGL_CFLAGS)
 console-gl.o-cflags += $(OPENGL_CFLAGS)
+egl-helpers.o-cflags += $(OPENGL_CFLAGS)
 
 shader.o-libs += $(OPENGL_LIBS)
 console-gl.o-libs += $(OPENGL_LIBS)
+egl-helpers.o-libs += $(OPENGL_LIBS)
ui/egl-helpers.c new file +143 -0

143 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#6 lore raw

Re: [Qemu-devel] [PATCH 3/4] ui: add egl-helpers

Quoted 101 lines · Gerd Hoffmann

Add helper functions to initialize OpenGL using egl.

---
  configure                |   2 +-
  include/ui/egl-helpers.h |  16 ++++++
  ui/Makefile.objs         |   3 +
  ui/egl-helpers.c         | 143 +++++++++++++++++++++++++++++++++++++++++++++++
  4 files changed, 163 insertions(+), 1 deletion(-)

create mode 100644 include/ui/egl-helpers.h
create mode 100644 ui/egl-helpers.c

configure +1 -1
index df1048a..e0e6b54 100755
@@ -3153,7 +3153,7 @@ else
  fi
 
  if test "$opengl" != "no" ; then
-  opengl_pkgs="gl glesv2 epoxy"
+  opengl_pkgs="gl glesv2 epoxy egl"
    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"
include/ui/egl-helpers.h new file +16 -0
new file mode 100644
index 0000000..5ad5dc3
@@ -0,0 +1,16 @@
+#ifndef EGL_HELPERS_H
+#define EGL_HELPERS_H
+
+#include <epoxy/gl.h>
+#include <epoxy/egl.h>
+
+extern EGLDisplay *qemu_egl_display;
+extern EGLConfig qemu_egl_config;
+
+EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, Window win);
+
+int qemu_egl_init_dpy(EGLNativeDisplayType dpy, bool gles, bool debug);
+EGLContext qemu_egl_init_ctx(void);
+bool qemu_egl_has_ext(const char *haystack, const char *needle);
+
+#endif /* EGL_HELPERS_H */
ui/Makefile.objs +3 -0
index 029a42a..5c46870 100644
@@ -30,11 +30,14 @@ sdl.mo-cflags := $(SDL_CFLAGS)
  ifeq ($(CONFIG_OPENGL),y)
  common-obj-y += shader.o
  common-obj-y += console-gl.o
+common-obj-y += egl-helpers.o
  endif
 
  gtk.o-cflags := $(GTK_CFLAGS) $(VTE_CFLAGS)
  shader.o-cflags += $(OPENGL_CFLAGS)
  console-gl.o-cflags += $(OPENGL_CFLAGS)
+egl-helpers.o-cflags += $(OPENGL_CFLAGS)
 
  shader.o-libs += $(OPENGL_LIBS)
  console-gl.o-libs += $(OPENGL_LIBS)
+egl-helpers.o-libs += $(OPENGL_LIBS)
ui/egl-helpers.c new file +29 -0
new file mode 100644
index 0000000..4dcca38
@@ -0,0 +1,143 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <glob.h>
+
+#include "ui/egl-helpers.h"
+
+EGLDisplay *qemu_egl_display;
+EGLConfig qemu_egl_config;
+
+/* ---------------------------------------------------------------------- */
+
+static int egl_debug;
+
+#define egl_dbg(_x ...)                          \
+    do {                                         \
+        if (egl_debug) {                         \
+            fprintf(stderr, "egl: " _x);         \
+        }                                        \
+    } while (0);
+
+/* ---------------------------------------------------------------------- */
+
+EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, Window win)

ui/egl-helpers.c line 39

Quoted 10 lines
ui/egl-helpers.c new file +10 -0
+{
+    EGLSurface esurface;
+    EGLBoolean b;
+
+    egl_dbg("eglCreateWindowSurface (x11 win id 0x%lx) ...\n",
+            (unsigned long) win);
+    esurface = eglCreateWindowSurface(qemu_egl_display,
+                                      qemu_egl_config,
+                                      (EGLNativeWindowType)win, NULL);
+    if (!esurface) {

Since I don't have any insights into EGL other than looking up the functions online, all I can do is nitpick:

The spec says it's EGL_NO_SURFACE (which probably is 0/NULL, but anyway...).

ui/egl-helpers.c line 45

Quoted 6 lines
ui/egl-helpers.c new file +6 -0
+        fprintf(stderr, "egl: eglCreateWindowSurface failed\n");
+        return NULL;
+    }
+
+    b = eglMakeCurrent(qemu_egl_display, esurface, esurface, ectx);
+    if (!b) {

EGL_FALSE, but assuming that is 0 is pretty reasonable, I guess. :-)

Quoted 7 lines
ui/egl-helpers.c new file +7 -0
+        fprintf(stderr, "egl: eglMakeCurrent failed\n");
+        return NULL;
+    }
+
+    return esurface;
+}
+

ui/egl-helpers.c line 62

Quoted 10 lines
ui/egl-helpers.c new file +10 -0
+/* ---------------------------------------------------------------------- */
+
+int qemu_egl_init_dpy(EGLNativeDisplayType dpy, bool gles, bool debug)
+{
+    static const EGLint conf_att_gl[] = {
+        EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
+        EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
+        EGL_RED_SIZE,   1,
+        EGL_GREEN_SIZE, 1,
+        EGL_BLUE_SIZE,  1,

Wouldn't it be more like 5, 6, 5? Apparently it doesn't really matter whether one specifies 1 or e.g. 5, as long as there is a configuration with equal to or more than 5 bits; but we won't be able to work with less than 5/6/5 anyway...

Quoted 15 lines
ui/egl-helpers.c new file +15 -0
+        EGL_ALPHA_SIZE, 0,
+        EGL_NONE,
+    };
+    static const EGLint conf_att_gles[] = {
+        EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
+        EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+        EGL_RED_SIZE,   1,
+        EGL_GREEN_SIZE, 1,
+        EGL_BLUE_SIZE,  1,
+        EGL_ALPHA_SIZE, 0,
+        EGL_NONE,
+    };
+    EGLint major, minor;
+    EGLBoolean b;
+    EGLint n;

ui/egl-helpers.c line 87

Quoted 10 lines
ui/egl-helpers.c new file +10 -0
+
+    if (debug) {
+        egl_debug = 1;
+        setenv("EGL_LOG_LEVEL", "debug", true);
+        setenv("LIBGL_DEBUG", "verbose", true);
+    }
+
+    egl_dbg("eglGetDisplay (dpy %p) ...\n", dpy);
+    qemu_egl_display = eglGetDisplay(dpy);
+    if (!qemu_egl_display) {

EGL_NO_DISPLAY

ui/egl-helpers.c line 97

Quoted 10 lines
ui/egl-helpers.c new file +10 -0
+        fprintf(stderr, "egl: eglGetDisplay failed\n");
+        return -1;
+    }
+
+    egl_dbg("eglInitialize ...\n");
+    b = eglInitialize(qemu_egl_display, &major, &minor);
+    if (!b) {
+        fprintf(stderr, "egl: eglInitialize failed\n");
+        return -1;
+    }

Should we care for eglTerminate() after this point (on error) or do we just assume there's no hope on failure anyway?

ui/egl-helpers.c line 109

Quoted 12 lines
ui/egl-helpers.c new file +12 -0
+
+    egl_dbg("eglBindAPI ...\n");
+    b = eglBindAPI(gles ? EGL_OPENGL_ES_API : EGL_OPENGL_API);
+    if (!b) {
+        fprintf(stderr, "egl: eglBindAPI failed\n");
+        return -1;
+    }
+
+    egl_dbg("eglChooseConfig ...\n");
+    b = eglChooseConfig(qemu_egl_display,
+                        gles ? conf_att_gles : conf_att_gl,
+                        &qemu_egl_config, 1, &n);

Well... It would be sad if the system actually supported true color (like basically any system everywhere) and we get some 5/6/5 configuration here (or even worse). I do think it would be better to actually receive the whole list and then scan through it to find the best configuration; if you want to keep it this way, we probably really have to make the attributes above reflect the minimum requirements (5/6/5 for R/G/B bit sizes).

Quoted 11 lines
ui/egl-helpers.c new file +11 -0
+    if (!b || n != 1) {
+        fprintf(stderr, "egl: eglChooseConfig failed\n");
+        return -1;
+    }
+
+    return 0;
+}
+
+EGLContext qemu_egl_init_ctx(void)
+{
+    static const EGLint ctx_att[] = {

ui/egl-helpers.c line 130

Quoted 10 lines
ui/egl-helpers.c new file +10 -0
+        EGL_CONTEXT_CLIENT_VERSION, 2,
+        EGL_NONE
+    };
+
+    EGLContext ectx;
+    EGLBoolean b;
+
+    egl_dbg("eglCreateContext ...\n");
+    ectx = eglCreateContext(qemu_egl_display, qemu_egl_config,
+                            EGL_NO_CONTEXT, ctx_att);

The manpage says specifying EGL_CONTEXT_CLIENT_VERSION is only valid when creating an OpenGL ES context.

ui/egl-helpers.c line 131

Quoted 1 line
ui/egl-helpers.c new file +1 -0
+    if (!ectx) {

EGL_NO_CONTEXT :-)

ui/egl-helpers.c line 136

Quoted 5 lines
ui/egl-helpers.c new file +5 -0
+        fprintf(stderr, "egl: eglCreateContext failed\n");
+        return NULL;
+    }
+
+    b = eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, ectx);

What is this call for? So that some rudimentary OpenGL operations can be executed which don't need access to a framebuffer?

Max

Quoted 7 lines
ui/egl-helpers.c new file +7 -0
+    if (!b) {
+        fprintf(stderr, "egl: eglMakeCurrent failed\n");
+        return NULL;
+    }
+
+    return ectx;
+}
#7 lore raw

Re: [Qemu-devel] [PATCH 3/4] ui: add egl-helpers

Hi,

Quoted 9 lines

ui/egl-helpers.c line 97

Quoted 6 lines
ui/egl-helpers.c new file +6 -0
+    egl_dbg("eglInitialize ...\n");
+    b = eglInitialize(qemu_egl_display, &major, &minor);
+    if (!b) {
+        fprintf(stderr, "egl: eglInitialize failed\n");
+        return -1;
+    }

Should we care for eglTerminate() after this point (on error) or do we just assume there's no hope on failure anyway?

Currently qemu will exit() on failure anyway.

Quoted 8 lines

ui/egl-helpers.c line 109

Quoted 4 lines
ui/egl-helpers.c new file +4 -0
+    egl_dbg("eglChooseConfig ...\n");
+    b = eglChooseConfig(qemu_egl_display,
+                        gles ? conf_att_gles : conf_att_gl,
+                        &qemu_egl_config, 1, &n);

Well... It would be sad if the system actually supported true color (like basically any system everywhere) and we get some 5/6/5 configuration here (or even worse).

I'd expect the system to simply return the best config here ...

Quoted 1 line

(5/6/5 for R/G/B bit sizes).

Fixed that.

Quoted 8 lines

ui/egl-helpers.c line 136

Quoted 5 lines
ui/egl-helpers.c new file +5 -0
+        fprintf(stderr, "egl: eglCreateContext failed\n");
+        return NULL;
+    }
+
+    b = eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, ectx);

What is this call for? So that some rudimentary OpenGL operations can be executed which don't need access to a framebuffer?

Yes.

Saw this in sample code: First make context active without surface, then create surface, then make context active again, this time with the fresh created surface.

Which made me think it is probably a good idea to make the new context active even without surface.

cheers,
Gerd

#8 lore raw

PATCH 4/4 gtk: add opengl support, using egl

In reply to Gerd Hoffmann

This adds opengl rendering support to the gtk ui, using egl. It's off by default for now, use 'qemu -display gtk,gl=on' to play with this.

Note that gtk got native opengl support with release 3.16. There most likely will be a separate implementation for 3.16+, using the native gtk opengl support. This patch covers older versions (and for the time being 3.16 too, hopefully without rendering quirks).

---
 include/ui/console.h |   2 +-
 include/ui/gtk.h     |  23 +++++++++
 ui/Makefile.objs     |   3 ++
 ui/gtk-egl.c         | 141 +++++++++++++++++++++++++++++++++++++++++++++++++++
 ui/gtk.c             |  77 ++++++++++++++++++++++------
 vl.c                 |  11 +++-
 6 files changed, 240 insertions(+), 17 deletions(-)
 create mode 100644 ui/gtk-egl.c
include/ui/console.h +1 -1
index 383dec2..6f7550e 100644
@@ -393,7 +393,7 @@ void curses_display_init(DisplayState *ds, int full_screen);
 int index_from_key(const char *key);
 
 /* gtk.c */
-void early_gtk_display_init(void);
+void early_gtk_display_init(int opengl);
 void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover);
 
 #endif
include/ui/gtk.h +23 -0
index b750845..ee6dffd 100644
@@ -22,6 +22,10 @@
 #include <X11/XKBlib.h>
 #endif
 
+#if defined(CONFIG_OPENGL)
+#include "ui/egl-helpers.h"
+#endif
+
 /* Compatibility define to let us build on both Gtk2 and Gtk3 */
 #if GTK_CHECK_VERSION(3, 0, 0)
 static inline void gdk_drawable_get_size(GdkWindow *w, gint *ww, gint *wh)
@@ -41,6 +45,12 @@ typedef struct VirtualGfxConsole {
     cairo_surface_t *surface;
     double scale_x;
     double scale_y;
+#if defined(CONFIG_OPENGL)
+    ConsoleGLState *gls;
+    EGLContext ectx;
+    EGLSurface esurface;
+    int glupdates;
+#endif
 } VirtualGfxConsole;
 
 #if defined(CONFIG_VTE)
@@ -73,4 +83,17 @@ typedef struct VirtualConsole {
     };
 } VirtualConsole;
 
+/* ui/gtk.c */
+void gd_update_windowsize(VirtualConsole *vc);
+
+/* ui/gtk-egl.c */
+void gd_egl_init(VirtualConsole *vc);
+void gd_egl_draw(VirtualConsole *vc);
+void gd_egl_update(DisplayChangeListener *dcl,
+                   int x, int y, int w, int h);
+void gd_egl_refresh(DisplayChangeListener *dcl);
+void gd_egl_switch(DisplayChangeListener *dcl,
+                   DisplaySurface *surface);
+void gtk_egl_init(void);
+
 #endif /* UI_GTK_H */
ui/Makefile.objs +3 -0
index 5c46870..023914c 100644
@@ -31,13 +31,16 @@ ifeq ($(CONFIG_OPENGL),y)
 common-obj-y += shader.o
 common-obj-y += console-gl.o
 common-obj-y += egl-helpers.o
+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-libs += $(OPENGL_LIBS)
 shader.o-libs += $(OPENGL_LIBS)
 console-gl.o-libs += $(OPENGL_LIBS)
 egl-helpers.o-libs += $(OPENGL_LIBS)
ui/gtk-egl.c new file +141 -0

141 lines not on this page · raw message

ui/gtk.c +62 -15

120 lines not on this page · raw message

vl.c +10 -1
index 15bccc4..26b1e7e 100644
@@ -2047,6 +2047,15 @@ static DisplayType select_display(const char *p)
                 } else {
                     goto invalid_gtk_args;
                 }
+            } else if (strstart(opts, ",gl=", &nextopt)) {
+                opts = nextopt;
+                if (strstart(opts, "on", &nextopt)) {
+                    request_opengl = 1;
+                } else if (strstart(opts, "off", &nextopt)) {
+                    request_opengl = 0;
+                } else {
+                    goto invalid_gtk_args;
+                }
             } else {
             invalid_gtk_args:
                 fprintf(stderr, "Invalid GTK option string: %s\n", p);
@@ -4012,7 +4021,7 @@ int main(int argc, char **argv, char **envp)
 
 #if defined(CONFIG_GTK)
     if (display_type == DT_GTK) {
-        early_gtk_display_init();
+        early_gtk_display_init(request_opengl);
     }
 #endif
 #if defined(CONFIG_SDL)
Signature · 1 line
1.8.3.1
#9 lore raw

Re: [Qemu-devel] [PATCH 4/4] gtk: add opengl support, using egl

Quoted 19 lines · Gerd Hoffmann

This adds opengl rendering support to the gtk ui, using egl. It's off by default for now, use 'qemu -display gtk,gl=on' to play with this.

Note that gtk got native opengl support with release 3.16. There most likely will be a separate implementation for 3.16+, using the native gtk opengl support. This patch covers older versions (and for the time being 3.16 too, hopefully without rendering quirks).

---
  include/ui/console.h |   2 +-
  include/ui/gtk.h     |  23 +++++++++
  ui/Makefile.objs     |   3 ++
  ui/gtk-egl.c         | 141 +++++++++++++++++++++++++++++++++++++++++++++++++++
  ui/gtk.c             |  77 ++++++++++++++++++++++------
  vl.c                 |  11 +++-
  6 files changed, 240 insertions(+), 17 deletions(-)
Quoted 1 line

create mode 100644 ui/gtk-egl.c

I can't give any R-b, because that would require really digging into Gtk... The code is pretty similar to the SDL code, though (not by chance I guess), so it looks fine to me. If it would compile, that is, see below.

(It does work with Gtk 2, though)

((at least on my laptop with mesa; on my desktop with fglrx, creating the shader fails, which may or may not have to do something with "libEGL warning: DRI2: failed to authenticate" (which is probably in turn my own fault for using a proprietary driver))) Konsole output

[snip]

Quoted 4 lines
ui/gtk.c +0 -0
index c58028f..bf66014 100644

[snip]

Quoted 8 lines
ui/gtk.c +3 -1
@@ -1713,7 +1737,16 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc,
      gtk_notebook_append_page(GTK_NOTEBOOK(s->notebook),
                               vc->tab_item, gtk_label_new(vc->label));
 
-    vc->gfx.dcl.ops = &dcl_ops;
+#if defined(CONFIG_OPENGL)
+    if (display_opengl) {
+        gtk_widget_set_double_buffered(vc->gfx.drawing_area, FALSE);
Quoted 1 line · gcc

Konsole output qemu/ui/gtk.c:1742:9: Fehler: »gtk_widget_set_double_buffered« is deprecated (declared at /usr/include/gtk-3.0/gtk/gtkwidget.h:896) [-Werror=deprecated-declarations]

(yes, the mix of German and English is gcc's doing)

But then again it didn't compile before, either: qemu/ui/gtk.c:1927:5: Fehler: »gdk_cursor_new« is deprecated (declared at /usr/include/gtk-3.0/gdk/gdkcursor.h:223) [-Werror=deprecated-declarations]

But that function was deprecated in 3.16, gtk_widget_set_double_buffered() was deprecated in 3.14 already (as far as I can see from the header file alone).

Max

#10 lore raw

Re: [Qemu-devel] [PATCH 4/4] gtk: add opengl support, using egl

Hi,

Quoted 3 lines

I can't give any R-b, because that would require really digging into Gtk... The code is pretty similar to the SDL code, though (not by chance I guess),

Indeed ;)

Quoted 8 lines

so it looks fine to me. If it would compile, that is, see below.

(It does work with Gtk 2, though)

((at least on my laptop with mesa; on my desktop with fglrx, creating the shader fails, which may or may not have to do something with "libEGL warning: DRI2: failed to authenticate" (which is probably in turn my own fault for using a proprietary driver)))

Could also be selinux.

Quoted 8 lines
Quoted 3 lines
ui/gtk.c +3 -0
+#if defined(CONFIG_OPENGL)
+    if (display_opengl) {
+        gtk_widget_set_double_buffered(vc->gfx.drawing_area, FALSE);
Quoted 1 line · gcc

qemu/ui/gtk.c:1742:9: Fehler: »gtk_widget_set_double_buffered« is

deprecated (declared at /usr/include/gtk-3.0/gtk/gtkwidget.h:896) [-Werror=deprecated-declarations]

Yep, that is a bit awkward.

Deprecated because gtk_widget_set_double_buffered() doesn't work with the wayland backend. The switch simply doesn't make sense with the wayland rendering pipeline, and the egl rendering might not work on wayland because of that (/me didn't try).

Nevertheless gtk_widget_set_double_buffered() is required to make gl rendering work (on X11 backend), for versions older than 3.16. On 3.16+ we can use the opengl support provided by gtk instead. Code for that still needs to be written though.

Quoted 4 lines

But then again it didn't compile before, either: qemu/ui/gtk.c:1927:5:
Fehler: »gdk_cursor_new« is deprecated (declared
at /usr/include/gtk-3.0/gdk/gdkcursor.h:223) [-Werror=deprecated-declarations]

Saw your patch for that, thanks.

Quoted 2 lines

gtk_widget_set_double_buffered() was deprecated in 3.14 already (as far as I can see from the header file alone).

They should have done that in 3.16 IMO ...

cheers,
Gerd

#11 lore raw

Re: [Qemu-devel] [PATCH 4/4] gtk: add opengl support, using egl

Quoted 9 lines · Gerd Hoffmann
   Hi,
Quoted 3 lines

I can't give any R-b, because that would require really digging into Gtk... The code is pretty similar to the SDL code, though (not by chance I guess),

Indeed ;)

Quoted 2 lines

so it looks fine to me. If it would compile, that is, see below.

Quoted 7 lines
Quoted 6 lines

(It does work with Gtk 2, though)

((at least on my laptop with mesa; on my desktop with fglrx, creating the shader fails, which may or may not have to do something with "libEGL warning: DRI2: failed to authenticate" (which is probably in turn my own fault for using a proprietary driver)))

Could also be selinux.

Except I don't use SELinux (here). I know, I know, shame on me.

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
ui/gtk.c +3 -0
+#if defined(CONFIG_OPENGL)
+    if (display_opengl) {
+        gtk_widget_set_double_buffered(vc->gfx.drawing_area, FALSE);
Quoted 1 line · gcc

qemu/ui/gtk.c:1742:9: Fehler: »gtk_widget_set_double_buffered« is

Quoted 8 lines
Quoted 2 lines

deprecated (declared at /usr/include/gtk-3.0/gtk/gtkwidget.h:896) [-Werror=deprecated-declarations]

Yep, that is a bit awkward.

Deprecated because gtk_widget_set_double_buffered() doesn't work with the wayland backend. The switch simply doesn't make sense with the wayland rendering pipeline, and the egl rendering might not work on wayland because of that (/me didn't try).

Right, but we cannot really tell gtk that we know what we're doing. :-)

Quoted 4 lines

Nevertheless gtk_widget_set_double_buffered() is required to make gl rendering work (on X11 backend), for versions older than 3.16. On 3.16+ we can use the opengl support provided by gtk instead. Code for that still needs to be written though.

Yep, that's what I thought of, too. But the problem is, as you yourself say, that 3.14 < 3.16...

Max

Quoted 12 lines
Quoted 4 lines

But then again it didn't compile before, either: qemu/ui/gtk.c:1927:5:
Fehler: »gdk_cursor_new« is deprecated (declared
at /usr/include/gtk-3.0/gdk/gdkcursor.h:223) [-Werror=deprecated-declarations]

Saw your patch for that, thanks.

Quoted 2 lines

gtk_widget_set_double_buffered() was deprecated in 3.14 already (as far as I can see from the header file alone).

They should have done that in 3.16 IMO ...

cheers,
Gerd