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