xref: /openbmc/qemu/include/ui/sdl2.h (revision bf41ab61)
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     SDL_GLContext winctx;
46     QKbdState *kbd;
47 #ifdef CONFIG_OPENGL
48     QemuGLShader *gls;
49     egl_fb guest_fb;
50     egl_fb win_fb;
51     bool y0_top;
52     bool scanout_mode;
53 #endif
54 };
55 
56 void sdl2_window_create(struct sdl2_console *scon);
57 void sdl2_window_destroy(struct sdl2_console *scon);
58 void sdl2_window_resize(struct sdl2_console *scon);
59 void sdl2_poll_events(struct sdl2_console *scon);
60 
61 void sdl2_process_key(struct sdl2_console *scon,
62                       SDL_KeyboardEvent *ev);
63 
64 void sdl2_2d_update(DisplayChangeListener *dcl,
65                     int x, int y, int w, int h);
66 void sdl2_2d_switch(DisplayChangeListener *dcl,
67                     DisplaySurface *new_surface);
68 void sdl2_2d_refresh(DisplayChangeListener *dcl);
69 void sdl2_2d_redraw(struct sdl2_console *scon);
70 bool sdl2_2d_check_format(DisplayChangeListener *dcl,
71                           pixman_format_code_t format);
72 
73 void sdl2_gl_update(DisplayChangeListener *dcl,
74                     int x, int y, int w, int h);
75 void sdl2_gl_switch(DisplayChangeListener *dcl,
76                     DisplaySurface *new_surface);
77 void sdl2_gl_refresh(DisplayChangeListener *dcl);
78 void sdl2_gl_redraw(struct sdl2_console *scon);
79 
80 QEMUGLContext sdl2_gl_create_context(DisplayGLCtx *dgc,
81                                      QEMUGLParams *params);
82 void sdl2_gl_destroy_context(DisplayGLCtx *dgc, QEMUGLContext ctx);
83 int sdl2_gl_make_context_current(DisplayGLCtx *dgc,
84                                  QEMUGLContext ctx);
85 
86 void sdl2_gl_scanout_disable(DisplayChangeListener *dcl);
87 void sdl2_gl_scanout_texture(DisplayChangeListener *dcl,
88                              uint32_t backing_id,
89                              bool backing_y_0_top,
90                              uint32_t backing_width,
91                              uint32_t backing_height,
92                              uint32_t x, uint32_t y,
93                              uint32_t w, uint32_t h,
94                              void *d3d_tex2d);
95 void sdl2_gl_scanout_flush(DisplayChangeListener *dcl,
96                            uint32_t x, uint32_t y, uint32_t w, uint32_t h);
97 
98 #endif /* SDL2_H */
99