xref: /openbmc/qemu/include/ui/sdl2.h (revision f550805d)
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 #include <SDL_syswm.h>
9 #ifdef CONFIG_SDL_IMAGE
10 # include <SDL_image.h>
11 #endif
12 
13 #ifdef CONFIG_OPENGL
14 # include "ui/egl-helpers.h"
15 #endif
16 
17 struct sdl2_console {
18     DisplayChangeListener dcl;
19     DisplaySurface *surface;
20     DisplayOptions *opts;
21     SDL_Texture *texture;
22     SDL_Window *real_window;
23     SDL_Renderer *real_renderer;
24     int idx;
25     int last_vm_running; /* per console for caption reasons */
26     int x, y, w, h;
27     int hidden;
28     int opengl;
29     int updates;
30     int idle_counter;
31     int ignore_hotkeys;
32     SDL_GLContext winctx;
33 #ifdef CONFIG_OPENGL
34     QemuGLShader *gls;
35     egl_fb guest_fb;
36     egl_fb win_fb;
37     bool y0_top;
38     bool scanout_mode;
39 #endif
40 };
41 
42 void sdl2_window_create(struct sdl2_console *scon);
43 void sdl2_window_destroy(struct sdl2_console *scon);
44 void sdl2_window_resize(struct sdl2_console *scon);
45 void sdl2_poll_events(struct sdl2_console *scon);
46 
47 void sdl2_reset_keys(struct sdl2_console *scon);
48 void sdl2_process_key(struct sdl2_console *scon,
49                       SDL_KeyboardEvent *ev);
50 
51 void sdl2_2d_update(DisplayChangeListener *dcl,
52                     int x, int y, int w, int h);
53 void sdl2_2d_switch(DisplayChangeListener *dcl,
54                     DisplaySurface *new_surface);
55 void sdl2_2d_refresh(DisplayChangeListener *dcl);
56 void sdl2_2d_redraw(struct sdl2_console *scon);
57 bool sdl2_2d_check_format(DisplayChangeListener *dcl,
58                           pixman_format_code_t format);
59 
60 void sdl2_gl_update(DisplayChangeListener *dcl,
61                     int x, int y, int w, int h);
62 void sdl2_gl_switch(DisplayChangeListener *dcl,
63                     DisplaySurface *new_surface);
64 void sdl2_gl_refresh(DisplayChangeListener *dcl);
65 void sdl2_gl_redraw(struct sdl2_console *scon);
66 
67 QEMUGLContext sdl2_gl_create_context(DisplayChangeListener *dcl,
68                                      QEMUGLParams *params);
69 void sdl2_gl_destroy_context(DisplayChangeListener *dcl, QEMUGLContext ctx);
70 int sdl2_gl_make_context_current(DisplayChangeListener *dcl,
71                                  QEMUGLContext ctx);
72 QEMUGLContext sdl2_gl_get_current_context(DisplayChangeListener *dcl);
73 
74 void sdl2_gl_scanout_disable(DisplayChangeListener *dcl);
75 void sdl2_gl_scanout_texture(DisplayChangeListener *dcl,
76                              uint32_t backing_id,
77                              bool backing_y_0_top,
78                              uint32_t backing_width,
79                              uint32_t backing_height,
80                              uint32_t x, uint32_t y,
81                              uint32_t w, uint32_t h);
82 void sdl2_gl_scanout_flush(DisplayChangeListener *dcl,
83                            uint32_t x, uint32_t y, uint32_t w, uint32_t h);
84 
85 #endif /* SDL2_H */
86