xref: /openbmc/qemu/include/ui/gtk.h (revision 0694dabe)
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     bool has_dmabuf;
52 #endif
53 } VirtualGfxConsole;
54 
55 #if defined(CONFIG_VTE)
56 typedef struct VirtualVteConsole {
57     GtkWidget *box;
58     GtkWidget *scrollbar;
59     GtkWidget *terminal;
60     Chardev *chr;
61     bool echo;
62 } VirtualVteConsole;
63 #endif
64 
65 typedef enum VirtualConsoleType {
66     GD_VC_GFX,
67     GD_VC_VTE,
68 } VirtualConsoleType;
69 
70 typedef struct VirtualConsole {
71     GtkDisplayState *s;
72     char *label;
73     GtkWidget *window;
74     GtkWidget *menu_item;
75     GtkWidget *tab_item;
76     GtkWidget *focus;
77     VirtualConsoleType type;
78     union {
79         VirtualGfxConsole gfx;
80 #if defined(CONFIG_VTE)
81         VirtualVteConsole vte;
82 #endif
83     };
84 } VirtualConsole;
85 
86 extern bool gtk_use_gl_area;
87 
88 /* ui/gtk.c */
89 void gd_update_windowsize(VirtualConsole *vc);
90 int gd_monitor_update_interval(GtkWidget *widget);
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_dmabuf(DisplayChangeListener *dcl,
138                                QemuDmaBuf *dmabuf);
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_disable(DisplayChangeListener *dcl);
147 void gd_gl_area_scanout_flush(DisplayChangeListener *dcl,
148                               uint32_t x, uint32_t y, uint32_t w, uint32_t h);
149 void gtk_gl_area_init(void);
150 int gd_gl_area_make_current(DisplayChangeListener *dcl,
151                             QEMUGLContext ctx);
152 
153 #endif /* UI_GTK_H */
154