2 * GTK UI -- egl opengl code.
4 * Note that gtk 3.16+ (released 2015-03-23) has a GtkGLArea widget,
5 * which is GtkDrawingArea like widget with opengl rendering support.
7 * This code handles opengl support on older gtk versions, using egl
8 * to get a opengl context for the X11 window.
10 * This work is licensed under the terms of the GNU GPL, version 2 or later.
11 * See the COPYING file in the top-level directory.
14 #include "qemu-common.h"
18 #include "ui/console.h"
20 #include "ui/egl-helpers.h"
22 #include "sysemu/sysemu.h"
24 /** DisplayState Callbacks (opengl version) **/
26 void gd_egl_init(VirtualConsole
*vc
)
28 GdkWindow
*gdk_window
= gtk_widget_get_window(vc
->gfx
.drawing_area
);
33 #if GTK_CHECK_VERSION(3, 0, 0)
34 Window x11_window
= gdk_x11_window_get_xid(gdk_window
);
36 Window x11_window
= gdk_x11_drawable_get_xid(gdk_window
);
42 vc
->gfx
.ectx
= qemu_egl_init_ctx();
43 vc
->gfx
.esurface
= qemu_egl_init_surface_x11(vc
->gfx
.ectx
, x11_window
);
45 assert(vc
->gfx
.esurface
);
48 void gd_egl_draw(VirtualConsole
*vc
)
53 if (!vc
->gfx
.gls
|| !vc
->gfx
.ds
) {
57 eglMakeCurrent(qemu_egl_display
, vc
->gfx
.esurface
,
58 vc
->gfx
.esurface
, vc
->gfx
.ectx
);
60 window
= gtk_widget_get_window(vc
->gfx
.drawing_area
);
61 gdk_drawable_get_size(window
, &ww
, &wh
);
62 surface_gl_setup_viewport(vc
->gfx
.gls
, vc
->gfx
.ds
, ww
, wh
);
63 surface_gl_render_texture(vc
->gfx
.gls
, vc
->gfx
.ds
);
65 eglSwapBuffers(qemu_egl_display
, vc
->gfx
.esurface
);
68 void gd_egl_update(DisplayChangeListener
*dcl
,
69 int x
, int y
, int w
, int h
)
71 VirtualConsole
*vc
= container_of(dcl
, VirtualConsole
, gfx
.dcl
);
73 if (!vc
->gfx
.gls
|| !vc
->gfx
.ds
) {
77 eglMakeCurrent(qemu_egl_display
, vc
->gfx
.esurface
,
78 vc
->gfx
.esurface
, vc
->gfx
.ectx
);
79 surface_gl_update_texture(vc
->gfx
.gls
, vc
->gfx
.ds
, x
, y
, w
, h
);
83 void gd_egl_refresh(DisplayChangeListener
*dcl
)
85 VirtualConsole
*vc
= container_of(dcl
, VirtualConsole
, gfx
.dcl
);
87 if (!vc
->gfx
.esurface
) {
89 if (!vc
->gfx
.esurface
) {
92 vc
->gfx
.gls
= console_gl_init_context();
94 surface_gl_create_texture(vc
->gfx
.gls
, vc
->gfx
.ds
);
98 graphic_hw_update(dcl
->con
);
100 if (vc
->gfx
.glupdates
) {
101 vc
->gfx
.glupdates
= 0;
106 void gd_egl_switch(DisplayChangeListener
*dcl
,
107 DisplaySurface
*surface
)
109 VirtualConsole
*vc
= container_of(dcl
, VirtualConsole
, gfx
.dcl
);
112 trace_gd_switch(vc
->label
, surface_width(surface
), surface_height(surface
));
115 surface_width(vc
->gfx
.ds
) == surface_width(surface
) &&
116 surface_height(vc
->gfx
.ds
) == surface_height(surface
)) {
120 surface_gl_destroy_texture(vc
->gfx
.gls
, vc
->gfx
.ds
);
121 vc
->gfx
.ds
= surface
;
123 surface_gl_create_texture(vc
->gfx
.gls
, vc
->gfx
.ds
);
127 gd_update_windowsize(vc
);
131 void gtk_egl_init(void)
133 GdkDisplay
*gdk_display
= gdk_display_get_default();
134 Display
*x11_display
= gdk_x11_display_get_xdisplay(gdk_display
);
136 if (qemu_egl_init_dpy(x11_display
, false, false) < 0) {