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