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