1 #ifndef UI_GTK_H 2 #define UI_GTK_H 3 4 /* Work around an -Wstrict-prototypes warning in GTK headers */ 5 #pragma GCC diagnostic push 6 #pragma GCC diagnostic ignored "-Wstrict-prototypes" 7 #include <gtk/gtk.h> 8 #pragma GCC diagnostic pop 9 10 #include <gdk/gdkkeysyms.h> 11 12 #ifdef GDK_WINDOWING_X11 13 #include <gdk/gdkx.h> 14 #include <X11/XKBlib.h> 15 #endif 16 17 #ifdef GDK_WINDOWING_WAYLAND 18 #include <gdk/gdkwayland.h> 19 #endif 20 21 #include "ui/kbd-state.h" 22 #if defined(CONFIG_OPENGL) 23 #include "ui/egl-helpers.h" 24 #include "ui/egl-context.h" 25 #endif 26 27 typedef struct GtkDisplayState GtkDisplayState; 28 29 typedef struct VirtualGfxConsole { 30 GtkWidget *drawing_area; 31 DisplayChangeListener dcl; 32 QKbdState *kbd; 33 DisplaySurface *ds; 34 pixman_image_t *convert; 35 cairo_surface_t *surface; 36 double scale_x; 37 double scale_y; 38 #if defined(CONFIG_OPENGL) 39 QemuGLShader *gls; 40 EGLContext ectx; 41 EGLSurface esurface; 42 int glupdates; 43 int x, y, w, h; 44 egl_fb guest_fb; 45 egl_fb win_fb; 46 egl_fb cursor_fb; 47 int cursor_x; 48 int cursor_y; 49 bool y0_top; 50 bool scanout_mode; 51 #endif 52 } VirtualGfxConsole; 53 54 #if defined(CONFIG_VTE) 55 typedef struct VirtualVteConsole { 56 GtkWidget *box; 57 GtkWidget *scrollbar; 58 GtkWidget *terminal; 59 Chardev *chr; 60 bool echo; 61 } VirtualVteConsole; 62 #endif 63 64 typedef enum VirtualConsoleType { 65 GD_VC_GFX, 66 GD_VC_VTE, 67 } VirtualConsoleType; 68 69 typedef struct VirtualConsole { 70 GtkDisplayState *s; 71 char *label; 72 GtkWidget *window; 73 GtkWidget *menu_item; 74 GtkWidget *tab_item; 75 GtkWidget *focus; 76 VirtualConsoleType type; 77 union { 78 VirtualGfxConsole gfx; 79 #if defined(CONFIG_VTE) 80 VirtualVteConsole vte; 81 #endif 82 }; 83 } VirtualConsole; 84 85 extern bool gtk_use_gl_area; 86 87 /* ui/gtk.c */ 88 void gd_update_windowsize(VirtualConsole *vc); 89 int gd_monitor_update_interval(GtkWidget *widget); 90 91 /* ui/gtk-egl.c */ 92 void gd_egl_init(VirtualConsole *vc); 93 void gd_egl_draw(VirtualConsole *vc); 94 void gd_egl_update(DisplayChangeListener *dcl, 95 int x, int y, int w, int h); 96 void gd_egl_refresh(DisplayChangeListener *dcl); 97 void gd_egl_switch(DisplayChangeListener *dcl, 98 DisplaySurface *surface); 99 QEMUGLContext gd_egl_create_context(DisplayChangeListener *dcl, 100 QEMUGLParams *params); 101 void gd_egl_scanout_disable(DisplayChangeListener *dcl); 102 void gd_egl_scanout_texture(DisplayChangeListener *dcl, 103 uint32_t backing_id, 104 bool backing_y_0_top, 105 uint32_t backing_width, 106 uint32_t backing_height, 107 uint32_t x, uint32_t y, 108 uint32_t w, uint32_t h); 109 void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl, 110 QemuDmaBuf *dmabuf); 111 void gd_egl_cursor_dmabuf(DisplayChangeListener *dcl, 112 QemuDmaBuf *dmabuf, bool have_hot, 113 uint32_t hot_x, uint32_t hot_y); 114 void gd_egl_cursor_position(DisplayChangeListener *dcl, 115 uint32_t pos_x, uint32_t pos_y); 116 void gd_egl_release_dmabuf(DisplayChangeListener *dcl, 117 QemuDmaBuf *dmabuf); 118 void gd_egl_scanout_flush(DisplayChangeListener *dcl, 119 uint32_t x, uint32_t y, uint32_t w, uint32_t h); 120 void gtk_egl_init(DisplayGLMode mode); 121 int gd_egl_make_current(DisplayChangeListener *dcl, 122 QEMUGLContext ctx); 123 124 /* ui/gtk-gl-area.c */ 125 void gd_gl_area_init(VirtualConsole *vc); 126 void gd_gl_area_draw(VirtualConsole *vc); 127 void gd_gl_area_update(DisplayChangeListener *dcl, 128 int x, int y, int w, int h); 129 void gd_gl_area_refresh(DisplayChangeListener *dcl); 130 void gd_gl_area_switch(DisplayChangeListener *dcl, 131 DisplaySurface *surface); 132 QEMUGLContext gd_gl_area_create_context(DisplayChangeListener *dcl, 133 QEMUGLParams *params); 134 void gd_gl_area_destroy_context(DisplayChangeListener *dcl, 135 QEMUGLContext ctx); 136 void gd_gl_area_scanout_texture(DisplayChangeListener *dcl, 137 uint32_t backing_id, 138 bool backing_y_0_top, 139 uint32_t backing_width, 140 uint32_t backing_height, 141 uint32_t x, uint32_t y, 142 uint32_t w, uint32_t h); 143 void gd_gl_area_scanout_flush(DisplayChangeListener *dcl, 144 uint32_t x, uint32_t y, uint32_t w, uint32_t h); 145 void gtk_gl_area_init(void); 146 QEMUGLContext gd_gl_area_get_current_context(DisplayChangeListener *dcl); 147 int gd_gl_area_make_current(DisplayChangeListener *dcl, 148 QEMUGLContext ctx); 149 150 #endif /* UI_GTK_H */ 151