xref: /openbmc/qemu/include/ui/sdl2.h (revision 7d87775f)
1 #ifndef SDL2_H
2 #define SDL2_H
3 
4 /* Avoid compiler warning because macro is redefined in SDL_syswm.h. */
5 #undef WIN32_LEAN_AND_MEAN
6 
7 #include <SDL.h>
8 
9 /* with Alpine / muslc SDL headers pull in directfb headers
10  * which in turn trigger warning about redundant decls for
11  * direct_waitqueue_deinit.
12  */
13 #pragma GCC diagnostic push
14 #pragma GCC diagnostic ignored "-Wredundant-decls"
15 
16 #include <SDL_syswm.h>
17 
18 #pragma GCC diagnostic pop
19 
20 #ifdef CONFIG_SDL_IMAGE
21 # include <SDL_image.h>
22 #endif
23 
24 #include "ui/kbd-state.h"
25 #ifdef CONFIG_OPENGL
26 # include "ui/egl-helpers.h"
27 #endif
28 
29 struct sdl2_console {
30     DisplayGLCtx dgc;
31     DisplayChangeListener dcl;
32     DisplaySurface *surface;
33     DisplayOptions *opts;
34     SDL_Texture *texture;
35     SDL_Window *real_window;
36     SDL_Renderer *real_renderer;
37     int idx;
38     int last_vm_running; /* per console for caption reasons */
39     int x, y, w, h;
40     int hidden;
41     int opengl;
42     int updates;
43     int idle_counter;
44     int ignore_hotkeys;
45     bool gui_keysym;
46     SDL_GLContext winctx;
47     QKbdState *kbd;
48 #ifdef CONFIG_OPENGL
49     QemuGLShader *gls;
50     egl_fb guest_fb;
51     egl_fb win_fb;
52     bool y0_top;
53     bool scanout_mode;
54 #endif
55 };
56 
57 void sdl2_window_create(struct sdl2_console *scon);
58 void sdl2_window_destroy(struct sdl2_console *scon);
59 void sdl2_window_resize(struct sdl2_console *scon);
60 void sdl2_poll_events(struct sdl2_console *scon);
61 
62 void sdl2_process_key(struct sdl2_console *scon,
63                       SDL_KeyboardEvent *ev);
64 void sdl2_release_modifiers(struct sdl2_console *scon);
65 
66 void sdl2_2d_update(DisplayChangeListener *dcl,
67                     int x, int y, int w, int h);
68 void sdl2_2d_switch(DisplayChangeListener *dcl,
69                     DisplaySurface *new_surface);
70 void sdl2_2d_refresh(DisplayChangeListener *dcl);
71 void sdl2_2d_redraw(struct sdl2_console *scon);
72 bool sdl2_2d_check_format(DisplayChangeListener *dcl,
73                           pixman_format_code_t format);
74 
75 void sdl2_gl_update(DisplayChangeListener *dcl,
76                     int x, int y, int w, int h);
77 void sdl2_gl_switch(DisplayChangeListener *dcl,
78                     DisplaySurface *new_surface);
79 void sdl2_gl_refresh(DisplayChangeListener *dcl);
80 void sdl2_gl_redraw(struct sdl2_console *scon);
81 
82 QEMUGLContext sdl2_gl_create_context(DisplayGLCtx *dgc,
83                                      QEMUGLParams *params);
84 void sdl2_gl_destroy_context(DisplayGLCtx *dgc, QEMUGLContext ctx);
85 int sdl2_gl_make_context_current(DisplayGLCtx *dgc,
86                                  QEMUGLContext ctx);
87 
88 void sdl2_gl_scanout_disable(DisplayChangeListener *dcl);
89 void sdl2_gl_scanout_texture(DisplayChangeListener *dcl,
90                              uint32_t backing_id,
91                              bool backing_y_0_top,
92                              uint32_t backing_width,
93                              uint32_t backing_height,
94                              uint32_t x, uint32_t y,
95                              uint32_t w, uint32_t h,
96                              void *d3d_tex2d);
97 void sdl2_gl_scanout_flush(DisplayChangeListener *dcl,
98                            uint32_t x, uint32_t y, uint32_t w, uint32_t h);
99 
100 #endif /* SDL2_H */
101