xref: /openbmc/qemu/include/ui/gtk.h (revision 9c2037d0)
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     ConsoleGLState *gls;
51     EGLContext ectx;
52     EGLSurface esurface;
53     int glupdates;
54     int x, y, w, h;
55     GLuint tex_id;
56     GLuint fbo_id;
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     CharDriverState *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(DisplayChangeListener *dcl,
107                     uint32_t backing_id, bool backing_y_0_top,
108                     uint32_t backing_width, uint32_t backing_height,
109                     uint32_t x, uint32_t y,
110                     uint32_t w, uint32_t h);
111 void gd_egl_scanout_flush(DisplayChangeListener *dcl,
112                           uint32_t x, uint32_t y, uint32_t w, uint32_t h);
113 void gtk_egl_init(void);
114 int gd_egl_make_current(DisplayChangeListener *dcl,
115                         QEMUGLContext ctx);
116 
117 /* ui/gtk-gl-area.c */
118 void gd_gl_area_init(VirtualConsole *vc);
119 void gd_gl_area_draw(VirtualConsole *vc);
120 void gd_gl_area_update(DisplayChangeListener *dcl,
121                        int x, int y, int w, int h);
122 void gd_gl_area_refresh(DisplayChangeListener *dcl);
123 void gd_gl_area_switch(DisplayChangeListener *dcl,
124                        DisplaySurface *surface);
125 QEMUGLContext gd_gl_area_create_context(DisplayChangeListener *dcl,
126                                         QEMUGLParams *params);
127 void gd_gl_area_destroy_context(DisplayChangeListener *dcl,
128                                 QEMUGLContext ctx);
129 void gd_gl_area_scanout(DisplayChangeListener *dcl,
130                         uint32_t backing_id, bool backing_y_0_top,
131                         uint32_t backing_width, uint32_t backing_height,
132                         uint32_t x, uint32_t y,
133                         uint32_t w, uint32_t h);
134 void gd_gl_area_scanout_flush(DisplayChangeListener *dcl,
135                               uint32_t x, uint32_t y, uint32_t w, uint32_t h);
136 void gtk_gl_area_init(void);
137 QEMUGLContext gd_gl_area_get_current_context(DisplayChangeListener *dcl);
138 int gd_gl_area_make_current(DisplayChangeListener *dcl,
139                             QEMUGLContext ctx);
140 
141 #endif /* UI_GTK_H */
142