4 #include "ui/qemu-pixman.h"
5 #include "qom/object.h"
6 #include "qapi/qmp/qdict.h"
7 #include "qemu/notify.h"
8 #include "monitor/monitor.h"
9 #include "qapi-types.h"
10 #include "qapi/error.h"
13 # include <GLES2/gl2.h>
14 # include <GLES2/gl2ext.h>
17 /* keyboard/mouse support */
19 #define MOUSE_EVENT_LBUTTON 0x01
20 #define MOUSE_EVENT_RBUTTON 0x02
21 #define MOUSE_EVENT_MBUTTON 0x04
22 #define MOUSE_EVENT_WHEELUP 0x08
23 #define MOUSE_EVENT_WHEELDN 0x10
25 /* identical to the ps/2 keyboard bits */
26 #define QEMU_SCROLL_LOCK_LED (1 << 0)
27 #define QEMU_NUM_LOCK_LED (1 << 1)
28 #define QEMU_CAPS_LOCK_LED (1 << 2)
31 #define GUI_REFRESH_INTERVAL_DEFAULT 30
32 #define GUI_REFRESH_INTERVAL_IDLE 3000
34 typedef void QEMUPutKBDEvent(void *opaque
, int keycode
);
35 typedef void QEMUPutLEDEvent(void *opaque
, int ledstate
);
36 typedef void QEMUPutMouseEvent(void *opaque
, int dx
, int dy
, int dz
, int buttons_state
);
38 typedef struct QEMUPutMouseEntry QEMUPutMouseEntry
;
39 typedef struct QEMUPutKbdEntry QEMUPutKbdEntry
;
40 typedef struct QEMUPutLEDEntry QEMUPutLEDEntry
;
42 QEMUPutKbdEntry
*qemu_add_kbd_event_handler(QEMUPutKBDEvent
*func
,
44 QEMUPutMouseEntry
*qemu_add_mouse_event_handler(QEMUPutMouseEvent
*func
,
45 void *opaque
, int absolute
,
47 void qemu_remove_mouse_event_handler(QEMUPutMouseEntry
*entry
);
48 void qemu_activate_mouse_event_handler(QEMUPutMouseEntry
*entry
);
50 QEMUPutLEDEntry
*qemu_add_led_event_handler(QEMUPutLEDEvent
*func
, void *opaque
);
51 void qemu_remove_led_event_handler(QEMUPutLEDEntry
*entry
);
53 void kbd_put_ledstate(int ledstate
);
55 struct MouseTransformInfo
{
56 /* Touchscreen resolution */
59 /* Calibration values as used/generated by tslib */
63 void hmp_mouse_set(Monitor
*mon
, const QDict
*qdict
);
65 /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
67 #define QEMU_KEY_ESC1(c) ((c) | 0xe100)
68 #define QEMU_KEY_BACKSPACE 0x007f
69 #define QEMU_KEY_UP QEMU_KEY_ESC1('A')
70 #define QEMU_KEY_DOWN QEMU_KEY_ESC1('B')
71 #define QEMU_KEY_RIGHT QEMU_KEY_ESC1('C')
72 #define QEMU_KEY_LEFT QEMU_KEY_ESC1('D')
73 #define QEMU_KEY_HOME QEMU_KEY_ESC1(1)
74 #define QEMU_KEY_END QEMU_KEY_ESC1(4)
75 #define QEMU_KEY_PAGEUP QEMU_KEY_ESC1(5)
76 #define QEMU_KEY_PAGEDOWN QEMU_KEY_ESC1(6)
77 #define QEMU_KEY_DELETE QEMU_KEY_ESC1(3)
79 #define QEMU_KEY_CTRL_UP 0xe400
80 #define QEMU_KEY_CTRL_DOWN 0xe401
81 #define QEMU_KEY_CTRL_LEFT 0xe402
82 #define QEMU_KEY_CTRL_RIGHT 0xe403
83 #define QEMU_KEY_CTRL_HOME 0xe404
84 #define QEMU_KEY_CTRL_END 0xe405
85 #define QEMU_KEY_CTRL_PAGEUP 0xe406
86 #define QEMU_KEY_CTRL_PAGEDOWN 0xe407
88 void kbd_put_keysym_console(QemuConsole
*s
, int keysym
);
89 bool kbd_put_qcode_console(QemuConsole
*s
, int qcode
);
90 void kbd_put_string_console(QemuConsole
*s
, const char *str
, int len
);
91 void kbd_put_keysym(int keysym
);
95 #define TYPE_QEMU_CONSOLE "qemu-console"
96 #define QEMU_CONSOLE(obj) \
97 OBJECT_CHECK(QemuConsole, (obj), TYPE_QEMU_CONSOLE)
98 #define QEMU_CONSOLE_GET_CLASS(obj) \
99 OBJECT_GET_CLASS(QemuConsoleClass, (obj), TYPE_QEMU_CONSOLE)
100 #define QEMU_CONSOLE_CLASS(klass) \
101 OBJECT_CLASS_CHECK(QemuConsoleClass, (klass), TYPE_QEMU_CONSOLE)
103 typedef struct QemuConsoleClass QemuConsoleClass
;
105 struct QemuConsoleClass
{
106 ObjectClass parent_class
;
109 #define QEMU_ALLOCATED_FLAG 0x01
112 uint8_t bits_per_pixel
;
113 uint8_t bytes_per_pixel
;
114 uint8_t depth
; /* color depth in bits */
115 uint32_t rmask
, gmask
, bmask
, amask
;
116 uint8_t rshift
, gshift
, bshift
, ashift
;
117 uint8_t rmax
, gmax
, bmax
, amax
;
118 uint8_t rbits
, gbits
, bbits
, abits
;
121 struct DisplaySurface
{
122 pixman_format_code_t format
;
123 pixman_image_t
*image
;
132 typedef struct QemuUIInfo
{
140 /* cursor data format is 32bit RGBA */
141 typedef struct QEMUCursor
{
148 QEMUCursor
*cursor_alloc(int width
, int height
);
149 void cursor_get(QEMUCursor
*c
);
150 void cursor_put(QEMUCursor
*c
);
151 QEMUCursor
*cursor_builtin_hidden(void);
152 QEMUCursor
*cursor_builtin_left_ptr(void);
153 void cursor_print_ascii_art(QEMUCursor
*c
, const char *prefix
);
154 int cursor_get_mono_bpl(QEMUCursor
*c
);
155 void cursor_set_mono(QEMUCursor
*c
,
156 uint32_t foreground
, uint32_t background
, uint8_t *image
,
157 int transparent
, uint8_t *mask
);
158 void cursor_get_mono_image(QEMUCursor
*c
, int foreground
, uint8_t *mask
);
159 void cursor_get_mono_mask(QEMUCursor
*c
, int transparent
, uint8_t *mask
);
161 typedef struct DisplayChangeListenerOps
{
162 const char *dpy_name
;
164 void (*dpy_refresh
)(DisplayChangeListener
*dcl
);
166 void (*dpy_gfx_update
)(DisplayChangeListener
*dcl
,
167 int x
, int y
, int w
, int h
);
168 void (*dpy_gfx_switch
)(DisplayChangeListener
*dcl
,
169 struct DisplaySurface
*new_surface
);
170 void (*dpy_gfx_copy
)(DisplayChangeListener
*dcl
,
171 int src_x
, int src_y
,
172 int dst_x
, int dst_y
, int w
, int h
);
173 bool (*dpy_gfx_check_format
)(DisplayChangeListener
*dcl
,
174 pixman_format_code_t format
);
176 void (*dpy_text_cursor
)(DisplayChangeListener
*dcl
,
178 void (*dpy_text_resize
)(DisplayChangeListener
*dcl
,
180 void (*dpy_text_update
)(DisplayChangeListener
*dcl
,
181 int x
, int y
, int w
, int h
);
183 void (*dpy_mouse_set
)(DisplayChangeListener
*dcl
,
184 int x
, int y
, int on
);
185 void (*dpy_cursor_define
)(DisplayChangeListener
*dcl
,
187 } DisplayChangeListenerOps
;
189 struct DisplayChangeListener
{
190 uint64_t update_interval
;
191 const DisplayChangeListenerOps
*ops
;
195 QLIST_ENTRY(DisplayChangeListener
) next
;
198 DisplayState
*init_displaystate(void);
199 DisplaySurface
*qemu_create_displaysurface_from(int width
, int height
,
200 pixman_format_code_t format
,
201 int linesize
, uint8_t *data
);
202 DisplaySurface
*qemu_create_displaysurface_guestmem(int width
, int height
,
203 pixman_format_code_t format
,
206 PixelFormat
qemu_default_pixelformat(int bpp
);
208 DisplaySurface
*qemu_create_displaysurface(int width
, int height
);
209 void qemu_free_displaysurface(DisplaySurface
*surface
);
211 static inline int is_surface_bgr(DisplaySurface
*surface
)
213 if (PIXMAN_FORMAT_BPP(surface
->format
) == 32 &&
214 PIXMAN_FORMAT_TYPE(surface
->format
) == PIXMAN_TYPE_ABGR
) {
221 static inline int is_buffer_shared(DisplaySurface
*surface
)
223 return !(surface
->flags
& QEMU_ALLOCATED_FLAG
);
226 void register_displaychangelistener(DisplayChangeListener
*dcl
);
227 void update_displaychangelistener(DisplayChangeListener
*dcl
,
229 void unregister_displaychangelistener(DisplayChangeListener
*dcl
);
231 bool dpy_ui_info_supported(QemuConsole
*con
);
232 int dpy_set_ui_info(QemuConsole
*con
, QemuUIInfo
*info
);
234 void dpy_gfx_update(QemuConsole
*con
, int x
, int y
, int w
, int h
);
235 void dpy_gfx_replace_surface(QemuConsole
*con
,
236 DisplaySurface
*surface
);
237 void dpy_gfx_copy(QemuConsole
*con
, int src_x
, int src_y
,
238 int dst_x
, int dst_y
, int w
, int h
);
239 void dpy_text_cursor(QemuConsole
*con
, int x
, int y
);
240 void dpy_text_update(QemuConsole
*con
, int x
, int y
, int w
, int h
);
241 void dpy_text_resize(QemuConsole
*con
, int w
, int h
);
242 void dpy_mouse_set(QemuConsole
*con
, int x
, int y
, int on
);
243 void dpy_cursor_define(QemuConsole
*con
, QEMUCursor
*cursor
);
244 bool dpy_cursor_define_supported(QemuConsole
*con
);
245 void dpy_gfx_update_dirty(QemuConsole
*con
,
246 MemoryRegion
*address_space
,
249 bool dpy_gfx_check_format(QemuConsole
*con
,
250 pixman_format_code_t format
);
252 static inline int surface_stride(DisplaySurface
*s
)
254 return pixman_image_get_stride(s
->image
);
257 static inline void *surface_data(DisplaySurface
*s
)
259 return pixman_image_get_data(s
->image
);
262 static inline int surface_width(DisplaySurface
*s
)
264 return pixman_image_get_width(s
->image
);
267 static inline int surface_height(DisplaySurface
*s
)
269 return pixman_image_get_height(s
->image
);
272 static inline int surface_bits_per_pixel(DisplaySurface
*s
)
274 int bits
= PIXMAN_FORMAT_BPP(s
->format
);
278 static inline int surface_bytes_per_pixel(DisplaySurface
*s
)
280 int bits
= PIXMAN_FORMAT_BPP(s
->format
);
281 return (bits
+ 7) / 8;
284 static inline pixman_format_code_t
surface_format(DisplaySurface
*s
)
291 typedef chtype console_ch_t
;
293 typedef unsigned long console_ch_t
;
295 static inline void console_write_ch(console_ch_t
*dest
, uint32_t ch
)
302 typedef struct GraphicHwOps
{
303 void (*invalidate
)(void *opaque
);
304 void (*gfx_update
)(void *opaque
);
305 void (*text_update
)(void *opaque
, console_ch_t
*text
);
306 void (*update_interval
)(void *opaque
, uint64_t interval
);
307 int (*ui_info
)(void *opaque
, uint32_t head
, QemuUIInfo
*info
);
310 QemuConsole
*graphic_console_init(DeviceState
*dev
, uint32_t head
,
311 const GraphicHwOps
*ops
,
313 void graphic_console_set_hwops(QemuConsole
*con
,
314 const GraphicHwOps
*hw_ops
,
317 void graphic_hw_update(QemuConsole
*con
);
318 void graphic_hw_invalidate(QemuConsole
*con
);
319 void graphic_hw_text_update(QemuConsole
*con
, console_ch_t
*chardata
);
321 QemuConsole
*qemu_console_lookup_by_index(unsigned int index
);
322 QemuConsole
*qemu_console_lookup_by_device(DeviceState
*dev
, uint32_t head
);
323 bool qemu_console_is_visible(QemuConsole
*con
);
324 bool qemu_console_is_graphic(QemuConsole
*con
);
325 bool qemu_console_is_fixedsize(QemuConsole
*con
);
326 char *qemu_console_get_label(QemuConsole
*con
);
327 int qemu_console_get_index(QemuConsole
*con
);
328 uint32_t qemu_console_get_head(QemuConsole
*con
);
329 QemuUIInfo
*qemu_console_get_ui_info(QemuConsole
*con
);
330 int qemu_console_get_width(QemuConsole
*con
, int fallback
);
331 int qemu_console_get_height(QemuConsole
*con
, int fallback
);
333 void text_consoles_set_display(DisplayState
*ds
);
334 void console_select(unsigned int index
);
335 void console_color_init(DisplayState
*ds
);
336 void qemu_console_resize(QemuConsole
*con
, int width
, int height
);
337 void qemu_console_copy(QemuConsole
*con
, int src_x
, int src_y
,
338 int dst_x
, int dst_y
, int w
, int h
);
339 DisplaySurface
*qemu_console_surface(QemuConsole
*con
);
342 typedef struct ConsoleGLState ConsoleGLState
;
344 ConsoleGLState
*console_gl_init_context(void);
345 void console_gl_fini_context(ConsoleGLState
*gls
);
346 bool console_gl_check_format(DisplayChangeListener
*dcl
,
347 pixman_format_code_t format
);
348 void surface_gl_create_texture(ConsoleGLState
*gls
,
349 DisplaySurface
*surface
);
350 void surface_gl_update_texture(ConsoleGLState
*gls
,
351 DisplaySurface
*surface
,
352 int x
, int y
, int w
, int h
);
353 void surface_gl_render_texture(ConsoleGLState
*gls
,
354 DisplaySurface
*surface
);
355 void surface_gl_destroy_texture(ConsoleGLState
*gls
,
356 DisplaySurface
*surface
);
357 void surface_gl_setup_viewport(ConsoleGLState
*gls
,
358 DisplaySurface
*surface
,
363 void sdl_display_early_init(int opengl
);
364 void sdl_display_init(DisplayState
*ds
, int full_screen
, int no_frame
);
367 void cocoa_display_init(DisplayState
*ds
, int full_screen
);
370 void vnc_display_init(const char *id
);
371 void vnc_display_open(const char *id
, Error
**errp
);
372 void vnc_display_add_client(const char *id
, int csock
, bool skipauth
);
373 char *vnc_display_local_addr(const char *id
);
375 int vnc_display_password(const char *id
, const char *password
);
376 int vnc_display_pw_expire(const char *id
, time_t expires
);
377 QemuOpts
*vnc_parse_func(const char *str
);
378 int vnc_init_func(QemuOpts
*opts
, void *opaque
);
380 static inline int vnc_display_password(const char *id
, const char *password
)
384 static inline int vnc_display_pw_expire(const char *id
, time_t expires
)
391 void curses_display_init(DisplayState
*ds
, int full_screen
);
394 int index_from_key(const char *key
);
397 void early_gtk_display_init(void);
398 void gtk_display_init(DisplayState
*ds
, bool full_screen
, bool grab_on_hover
);