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