gtk: add opengl support
v2 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.
v2: Fixes according to review by Max,
also added "Replace gdk_cursor_new" patch.
Gerd Hoffmann (4):
ui: use libexpoxy
ui: shader.h protect against double inclusion
ui: add egl-helpers
gtk: add opengl support, using egl
Max Reitz (1):
gtk: Replace gdk_cursor_new()
configure | 4 +- 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 | 148 +++++++++++++++++++++++++++++++++++++++++++++++ ui/gtk-egl.c | 141 ++++++++++++++++++++++++++++++++++++++++++++ ui/gtk.c | 82 +++++++++++++++++++++----- vl.c | 11 +++- 10 files changed, 420 insertions(+), 26 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
PATCH v2 1/5 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 | 4 ++-- include/ui/console.h | 3 +-- include/ui/shader.h | 5 +---- 3 files changed, 4 insertions(+), 8 deletions(-)
configure +2 -2
@@ -3153,14 +3153,14 @@ 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" opengl=yes else if test "$opengl" = "yes" ; then - feature_not_found "opengl" "Install GL devel (e.g. MESA)" + feature_not_found "opengl" "Please install opengl (mesa) devel pkgs: $opengl_pkgs" fi opengl_cflags="" opengl_libs=""
include/ui/console.h +1 -2
@@ -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
@@ -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
PATCH v2 2/5 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
@@ -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
PATCH v2 3/5 ui: add egl-helpers
In reply to Gerd HoffmannAdd helper functions to initialize OpenGL using egl.
--- configure | 2 +- include/ui/egl-helpers.h | 16 +++++ ui/Makefile.objs | 3 + ui/egl-helpers.c | 148 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 include/ui/egl-helpers.h create mode 100644 ui/egl-helpers.c
configure +1 -1
@@ -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
@@ -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
@@ -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 +148 -0
148 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 4/5 gtk: add opengl support, using egl
In reply to Gerd HoffmannThis 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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v2 5/5 gtk: Replace gdk_cursor_new()
In reply to Gerd HoffmannFrom: Max Reitz <[email protected]>
gdk_cursor_new() has been deprecated in GTK 3.16, it is recommended to use gdk_cursor_new_for_display() instead, so do that.
--- ui/gtk.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
ui/gtk.c +4 -1
@@ -1908,6 +1908,7 @@ void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover) {GtkDisplayState *s =g_malloc0 (sizeof (*s));char *filename; +GdkDisplay *window_display; s->window =gtk_window_new (GTK_WINDOW_TOPLEVEL );#if GTK_CHECK_VERSION (3 ,2 ,0 )
@@ -1924,7 +1925,9 @@ void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover)bindtextdomain ("qemu" ,CONFIG_QEMU_LOCALEDIR );textdomain ("qemu" ); - s->null_cursor =gdk_cursor_new (GDK_BLANK_CURSOR ); + window_display =gtk_widget_get_display (s->window); + s->null_cursor =gdk_cursor_new_for_display (window_display, +GDK_BLANK_CURSOR ); s->mouse_mode_notifier.notify = gd_mouse_mode_change;qemu_add_mouse_mode_change_notifier (&s->mouse_mode_notifier);
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v2 3/5] ui: add egl-helpers
In reply to Gerd HoffmannQuoted 11 lines · Gerd Hoffmann
Add helper functions to initialize OpenGL using egl.
Signed-off-by Gerd Hoffmann <[email protected]>--- configure | 2 +- include/ui/egl-helpers.h | 16 +++++ ui/Makefile.objs | 3 + ui/egl-helpers.c | 148 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 168 insertions(+), 1 deletion(-)create mode 100644
include/ui/egl-helpers.h
create mode 100644ui/egl-helpers.c
Fingers crossed that the first configuration returned by eglChooseConfig() really is the best one. :-)
Re: [Qemu-devel] [PATCH v2 4/5] gtk: add opengl support, using egl
In reply to Gerd HoffmannQuoted 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).
Signed-off-by Gerd Hoffmann <[email protected]>--- 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 do see the quandary with gtk 3.14 and 3.15 (gtk_widget_set_double_buffered() is deprecated, but we need it), but the problem is, with this patch, you simply cannot compile qemu on a gtk 3.14+ system with --with-gtkabi=3.0 and without --disable-opengl, which I don't think is right.
So at least the commit message is wrong, this patch does not cover 3.16. It would without -Werror (or with -Wno-deprecated-declarations), but that's enabled by default.
Once the native OpenGL support introduced by 3.16 is used, at least that'll be covered, but we'll still have to deal with 3.14 and 3.15. I think the right thing to do is to make configure disable OpenGL support if gtk 3.14+ is to be used (in the future, that would be 3.14/3.15 only). That, or pass -Wno-deprecated-declarations for compiling ui/gtk.c, but that seems very ugly to me.
Not planning to have OpenGL support for 3.14/3.15 I think is fine, but we have to make sure that OpenGL support cannot be silently enabled by configure and then break compilation of qemu.
Max
Re: [Qemu-devel] [PATCH v2 4/5] gtk: add opengl support, using egl
Hi,
Quoted 2 lines
only). That, or pass -Wno-deprecated-declarations for compiling
ui/gtk.c, but that seems very ugly to me.
We can also try some #pragma warn dance, to limit the -Wno-deprecated-declarations to a small code block.
We have something simliar already for a bug in the gtk2 headers.
cheers,
Gerd
Re: [Qemu-devel] [PATCH v2 4/5] gtk: add opengl support, using egl
Quoted 9 lines · Gerd Hoffmann
Hi,
Quoted 2 lines
only). That, or pass -Wno-deprecated-declarations for compiling
ui/gtk.c, but that seems very ugly to me.We can also try some #pragma warn dance, to limit the -Wno-deprecated-declarations to a small code block.
We have something simliar already for a bug in the gtk2 headers.
i.e. like this:
Quoted 1 line
From
21b26f0f0bc57c209381fd13c7ca01ea97354dfcMon Sep 17 00:00:00 2001
From: Gerd Hoffmann <[email protected]>
Date: Tue, 26 May 2015 11:52:08 +0200
Subject: [PATCH] gtk: silence gtk_widget_set_double_buffered warning
--- ui/gtk.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
ui/gtk.c +13 -0
@@ -1739,7 +1739,20 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc,#if defined(CONFIG_OPENGL )if (display_opengl) { +/* +* gtk_widget_set_double_buffered() was deprecated in 3.14. +* It is required for opengl rendering on X11 though. A +* proper replacement (native opengl support) is only +* available in 3.16+. Silence the warning if possible. +*/ +#ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif gtk_widget_set_double_buffered (vc->gfx.drawing_area, FALSE); +#ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE +#pragma GCC diagnostic pop +#endif vc->gfx.dcl.ops = &dcl_egl_ops; } else#endif
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v2 4/5] gtk: add opengl support, using egl
Quoted 10 lines · Gerd Hoffmann
Quoted 8 lines · Gerd Hoffmann
Hi,Quoted 2 lines
only). That, or pass -Wno-deprecated-declarations for compiling
ui/gtk.c, but that seems very ugly to me.We can also try some #pragma warn dance, to limit the -Wno-deprecated-declarations to a small code block.
We have something simliar already for a bug in the gtk2 headers.
i.e. like this:
I don't like it very much, but you're the maintainer, so if you deem it acceptable, I won't object. :-)
Google says clang supports GCC pragmas, so it should be fine, because I don't think qemu is supposed to work with any other compiler anyway...
Max
Re: [Qemu-devel] [PATCH v2 4/5] gtk: add opengl support, using egl
Quoted 6 lines · Max Reitz
Quoted 5 lines · Gerd Hoffmann
Quoted 4 lines · Gerd Hoffmann
Hi,Quoted 2 lines
only). That, or pass -Wno-deprecated-declarations for compiling
ui/gtk.c, but that seems very ugly to me.
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
We can also try some #pragma warn dance, to limit the -Wno-deprecated-declarations to a small code block.
We have something simliar already for a bug in the gtk2 headers.
i.e. like this:
I don't like it very much, but you're the maintainer, so if you deem it acceptable, I won't object. :-)
It's not pretty indeed.
But turning off deprecated declarations for the whole file (which would be a much less ugly one-liner in the Makefile) isn't a good solution either because gtk actually deprecates things now and then and I'd like us notice.
If someone has better ideas I'm all ears.
cheers,
Gerd