2 * QEMU SDL display driver
4 * Copyright (c) 2003 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 /* Ported SDL 1.2 code to 2.0 by Dave Airlie. */
26 /* Avoid compiler warning because macro is redefined in SDL_syswm.h. */
27 #undef WIN32_LEAN_AND_MEAN
31 #if SDL_MAJOR_VERSION == 2
32 #include <SDL_syswm.h>
34 #include "qemu-common.h"
35 #include "ui/console.h"
37 #include "sysemu/sysemu.h"
40 #include "sdl2-keymap.h"
42 static int sdl2_num_outputs
;
43 static struct sdl2_state
{
44 DisplayChangeListener dcl
;
45 DisplaySurface
*surface
;
47 SDL_Window
*real_window
;
48 SDL_Renderer
*real_renderer
;
50 int last_vm_running
; /* per console for caption reasons */
54 static SDL_Surface
*guest_sprite_surface
;
55 static int gui_grab
; /* if true, all keyboard/mouse events are grabbed */
57 static bool gui_saved_scaling
;
58 static int gui_saved_width
;
59 static int gui_saved_height
;
60 static int gui_saved_grab
;
61 static int gui_fullscreen
;
62 static int gui_noframe
;
63 static int gui_key_modifier_pressed
;
64 static int gui_keysym
;
65 static int gui_grab_code
= KMOD_LALT
| KMOD_LCTRL
;
66 static uint8_t modifiers_state
[SDL_NUM_SCANCODES
];
67 static SDL_Cursor
*sdl_cursor_normal
;
68 static SDL_Cursor
*sdl_cursor_hidden
;
69 static int absolute_enabled
;
70 static int guest_cursor
;
71 static int guest_x
, guest_y
;
72 static SDL_Cursor
*guest_sprite
;
73 static int scaling_active
;
74 static Notifier mouse_mode_notifier
;
76 static void sdl_update_caption(struct sdl2_state
*scon
);
78 static struct sdl2_state
*get_scon_from_window(uint32_t window_id
)
81 for (i
= 0; i
< sdl2_num_outputs
; i
++) {
82 if (sdl2_console
[i
].real_window
== SDL_GetWindowFromID(window_id
)) {
83 return &sdl2_console
[i
];
89 static void sdl_update(DisplayChangeListener
*dcl
,
90 int x
, int y
, int w
, int h
)
92 struct sdl2_state
*scon
= container_of(dcl
, struct sdl2_state
, dcl
);
94 DisplaySurface
*surf
= qemu_console_surface(dcl
->con
);
108 SDL_UpdateTexture(scon
->texture
, NULL
, surface_data(surf
),
109 surface_stride(surf
));
110 SDL_RenderCopy(scon
->real_renderer
, scon
->texture
, &rect
, &rect
);
111 SDL_RenderPresent(scon
->real_renderer
);
114 static void do_sdl_resize(struct sdl2_state
*scon
, int width
, int height
,
119 if (scon
->real_window
&& scon
->real_renderer
) {
120 if (width
&& height
) {
121 SDL_RenderSetLogicalSize(scon
->real_renderer
, width
, height
);
122 SDL_SetWindowSize(scon
->real_window
, width
, height
);
124 SDL_DestroyRenderer(scon
->real_renderer
);
125 SDL_DestroyWindow(scon
->real_window
);
126 scon
->real_renderer
= NULL
;
127 scon
->real_window
= NULL
;
130 if (!width
|| !height
) {
134 if (gui_fullscreen
) {
135 flags
|= SDL_WINDOW_FULLSCREEN
;
137 flags
|= SDL_WINDOW_RESIZABLE
;
140 scon
->real_window
= SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED
,
141 SDL_WINDOWPOS_UNDEFINED
,
142 width
, height
, flags
);
143 scon
->real_renderer
= SDL_CreateRenderer(scon
->real_window
, -1, 0);
144 sdl_update_caption(scon
);
148 static void sdl_switch(DisplayChangeListener
*dcl
,
149 DisplaySurface
*new_surface
)
151 struct sdl2_state
*scon
= container_of(dcl
, struct sdl2_state
, dcl
);
154 DisplaySurface
*old_surface
= scon
->surface
;
156 /* temporary hack: allows to call sdl_switch to handle scaling changes */
158 scon
->surface
= new_surface
;
161 if (!new_surface
&& idx
> 0) {
162 scon
->surface
= NULL
;
165 if (new_surface
== NULL
) {
166 do_sdl_resize(scon
, 0, 0, 0);
168 do_sdl_resize(scon
, surface_width(scon
->surface
),
169 surface_height(scon
->surface
), 0);
172 if (old_surface
&& scon
->texture
) {
173 SDL_DestroyTexture(scon
->texture
);
174 scon
->texture
= NULL
;
178 if (!scon
->texture
) {
179 if (surface_bits_per_pixel(scon
->surface
) == 16) {
180 format
= SDL_PIXELFORMAT_RGB565
;
181 } else if (surface_bits_per_pixel(scon
->surface
) == 32) {
182 format
= SDL_PIXELFORMAT_ARGB8888
;
185 scon
->texture
= SDL_CreateTexture(scon
->real_renderer
, format
,
186 SDL_TEXTUREACCESS_STREAMING
,
187 surface_width(new_surface
),
188 surface_height(new_surface
));
193 static void reset_keys(void)
197 for (i
= 0; i
< 256; i
++) {
198 if (modifiers_state
[i
]) {
199 int qcode
= sdl2_scancode_to_qcode
[i
];
200 qemu_input_event_send_key_qcode(NULL
, qcode
, false);
201 modifiers_state
[i
] = 0;
206 static void sdl_process_key(SDL_KeyboardEvent
*ev
)
208 int qcode
= sdl2_scancode_to_qcode
[ev
->keysym
.scancode
];
210 switch (ev
->keysym
.scancode
) {
212 case SDL_SCANCODE_NUMLOCKCLEAR
:
213 case SDL_SCANCODE_CAPSLOCK
:
214 /* SDL does not send the key up event, so we generate it */
215 qemu_input_event_send_key_qcode(NULL
, qcode
, true);
216 qemu_input_event_send_key_qcode(NULL
, qcode
, false);
219 case SDL_SCANCODE_LCTRL
:
220 case SDL_SCANCODE_LSHIFT
:
221 case SDL_SCANCODE_LALT
:
222 case SDL_SCANCODE_LGUI
:
223 case SDL_SCANCODE_RCTRL
:
224 case SDL_SCANCODE_RSHIFT
:
225 case SDL_SCANCODE_RALT
:
226 case SDL_SCANCODE_RGUI
:
227 if (ev
->type
== SDL_KEYUP
) {
228 modifiers_state
[ev
->keysym
.scancode
] = 0;
230 modifiers_state
[ev
->keysym
.scancode
] = 1;
234 qemu_input_event_send_key_qcode(NULL
, qcode
,
235 ev
->type
== SDL_KEYDOWN
);
239 static void sdl_update_caption(struct sdl2_state
*scon
)
241 char win_title
[1024];
242 char icon_title
[1024];
243 const char *status
= "";
245 if (!runstate_is_running()) {
246 status
= " [Stopped]";
247 } else if (gui_grab
) {
249 status
= " - Press Ctrl-Alt-Shift to exit mouse grab";
250 } else if (ctrl_grab
) {
251 status
= " - Press Right-Ctrl to exit mouse grab";
253 status
= " - Press Ctrl-Alt to exit mouse grab";
258 snprintf(win_title
, sizeof(win_title
), "QEMU (%s-%d)%s", qemu_name
,
260 snprintf(icon_title
, sizeof(icon_title
), "QEMU (%s)", qemu_name
);
262 snprintf(win_title
, sizeof(win_title
), "QEMU%s", status
);
263 snprintf(icon_title
, sizeof(icon_title
), "QEMU");
266 if (scon
->real_window
) {
267 SDL_SetWindowTitle(scon
->real_window
, win_title
);
271 static void sdl_hide_cursor(void)
277 if (qemu_input_is_absolute()) {
279 SDL_SetCursor(sdl_cursor_hidden
);
285 static void sdl_show_cursor(void)
291 if (!qemu_input_is_absolute()) {
294 (gui_grab
|| qemu_input_is_absolute() || absolute_enabled
)) {
295 SDL_SetCursor(guest_sprite
);
297 SDL_SetCursor(sdl_cursor_normal
);
302 static void sdl_grab_start(struct sdl2_state
*scon
)
305 * If the application is not active, do not try to enter grab state. This
306 * prevents 'SDL_WM_GrabInput(SDL_GRAB_ON)' from blocking all the
307 * application (SDL bug).
309 if (!(SDL_GetWindowFlags(scon
->real_window
) & SDL_WINDOW_INPUT_FOCUS
)) {
313 SDL_SetCursor(guest_sprite
);
314 if (!qemu_input_is_absolute() && !absolute_enabled
) {
315 SDL_WarpMouseInWindow(scon
->real_window
, guest_x
, guest_y
);
320 SDL_SetWindowGrab(scon
->real_window
, SDL_TRUE
);
322 sdl_update_caption(scon
);
325 static void sdl_grab_end(struct sdl2_state
*scon
)
327 SDL_SetWindowGrab(scon
->real_window
, SDL_FALSE
);
330 sdl_update_caption(scon
);
333 static void absolute_mouse_grab(struct sdl2_state
*scon
)
335 int mouse_x
, mouse_y
;
337 SDL_GetMouseState(&mouse_x
, &mouse_y
);
338 SDL_GetWindowSize(scon
->real_window
, &scr_w
, &scr_h
);
339 if (mouse_x
> 0 && mouse_x
< scr_w
- 1 &&
340 mouse_y
> 0 && mouse_y
< scr_h
- 1) {
341 sdl_grab_start(scon
);
345 static void sdl_mouse_mode_change(Notifier
*notify
, void *data
)
347 if (qemu_input_is_absolute()) {
348 if (!absolute_enabled
) {
349 absolute_enabled
= 1;
350 absolute_mouse_grab(&sdl2_console
[0]);
352 } else if (absolute_enabled
) {
353 if (!gui_fullscreen
) {
354 sdl_grab_end(&sdl2_console
[0]);
356 absolute_enabled
= 0;
360 static void sdl_send_mouse_event(struct sdl2_state
*scon
, int dx
, int dy
,
361 int dz
, int x
, int y
, int state
)
363 static uint32_t bmap
[INPUT_BUTTON_MAX
] = {
364 [INPUT_BUTTON_LEFT
] = SDL_BUTTON(SDL_BUTTON_LEFT
),
365 [INPUT_BUTTON_MIDDLE
] = SDL_BUTTON(SDL_BUTTON_MIDDLE
),
366 [INPUT_BUTTON_RIGHT
] = SDL_BUTTON(SDL_BUTTON_RIGHT
),
368 [INPUT_BUTTON_WHEEL_UP
] = SDL_BUTTON(SDL_BUTTON_WHEELUP
),
369 [INPUT_BUTTON_WHEEL_DOWN
] = SDL_BUTTON(SDL_BUTTON_WHEELDOWN
),
372 static uint32_t prev_state
;
374 if (prev_state
!= state
) {
375 qemu_input_update_buttons(scon
->dcl
.con
, bmap
, prev_state
, state
);
379 if (qemu_input_is_absolute()) {
381 int max_w
= 0, max_h
= 0;
382 int off_x
= 0, off_y
= 0;
383 int cur_off_x
= 0, cur_off_y
= 0;
386 for (i
= 0; i
< sdl2_num_outputs
; i
++) {
387 struct sdl2_state
*thiscon
= &sdl2_console
[i
];
388 if (thiscon
->real_window
&& thiscon
->surface
) {
389 SDL_GetWindowSize(thiscon
->real_window
, &scr_w
, &scr_h
);
390 cur_off_x
= thiscon
->x
;
391 cur_off_y
= thiscon
->y
;
392 if (scr_w
+ cur_off_x
> max_w
) {
393 max_w
= scr_w
+ cur_off_x
;
395 if (scr_h
+ cur_off_y
> max_h
) {
396 max_h
= scr_h
+ cur_off_y
;
398 if (i
== scon
->idx
) {
404 qemu_input_queue_abs(scon
->dcl
.con
, INPUT_AXIS_X
, off_x
+ x
, max_w
);
405 qemu_input_queue_abs(scon
->dcl
.con
, INPUT_AXIS_Y
, off_y
+ y
, max_h
);
406 } else if (guest_cursor
) {
411 qemu_input_queue_rel(scon
->dcl
.con
, INPUT_AXIS_X
, x
);
412 qemu_input_queue_rel(scon
->dcl
.con
, INPUT_AXIS_Y
, y
);
414 qemu_input_event_sync();
417 static void sdl_scale(struct sdl2_state
*scon
, int width
, int height
)
420 do_sdl_resize(scon
, width
, height
, bpp
);
424 static void toggle_full_screen(struct sdl2_state
*scon
)
426 int width
= surface_width(scon
->surface
);
427 int height
= surface_height(scon
->surface
);
428 int bpp
= surface_bits_per_pixel(scon
->surface
);
430 gui_fullscreen
= !gui_fullscreen
;
431 if (gui_fullscreen
) {
432 SDL_GetWindowSize(scon
->real_window
,
433 &gui_saved_width
, &gui_saved_height
);
434 gui_saved_scaling
= scaling_active
;
436 do_sdl_resize(scon
, width
, height
, bpp
);
439 gui_saved_grab
= gui_grab
;
440 sdl_grab_start(scon
);
442 if (gui_saved_scaling
) {
443 sdl_scale(scon
, gui_saved_width
, gui_saved_height
);
445 do_sdl_resize(scon
, width
, height
, 0);
447 if (!gui_saved_grab
) {
451 graphic_hw_invalidate(scon
->dcl
.con
);
452 graphic_hw_update(scon
->dcl
.con
);
455 static void handle_keydown(SDL_Event
*ev
)
458 struct sdl2_state
*scon
= get_scon_from_window(ev
->key
.windowID
);
461 mod_state
= (SDL_GetModState() & (gui_grab_code
| KMOD_LSHIFT
)) ==
462 (gui_grab_code
| KMOD_LSHIFT
);
463 } else if (ctrl_grab
) {
464 mod_state
= (SDL_GetModState() & KMOD_RCTRL
) == KMOD_RCTRL
;
466 mod_state
= (SDL_GetModState() & gui_grab_code
) == gui_grab_code
;
468 gui_key_modifier_pressed
= mod_state
;
470 if (gui_key_modifier_pressed
) {
471 switch (ev
->key
.keysym
.scancode
) {
473 toggle_full_screen(scon
);
477 if (scaling_active
) {
479 sdl_switch(&scon
->dcl
, NULL
);
480 graphic_hw_invalidate(scon
->dcl
.con
);
481 graphic_hw_update(scon
->dcl
.con
);
485 case SDL_SCANCODE_KP_PLUS
:
486 case SDL_SCANCODE_KP_MINUS
:
487 if (!gui_fullscreen
) {
490 SDL_GetWindowSize(scon
->real_window
, &scr_w
, &scr_h
);
492 width
= MAX(scr_w
+ (ev
->key
.keysym
.scancode
==
493 SDL_SCANCODE_KP_PLUS
? 50 : -50),
495 height
= (surface_height(scon
->surface
) * width
) /
496 surface_width(scon
->surface
);
498 sdl_scale(scon
, width
, height
);
499 graphic_hw_invalidate(NULL
);
500 graphic_hw_update(NULL
);
508 sdl_process_key(&ev
->key
);
512 static void handle_keyup(SDL_Event
*ev
)
515 struct sdl2_state
*scon
= get_scon_from_window(ev
->key
.windowID
);
518 mod_state
= (ev
->key
.keysym
.mod
& gui_grab_code
);
520 mod_state
= (ev
->key
.keysym
.mod
& (gui_grab_code
| KMOD_LSHIFT
));
522 if (!mod_state
&& gui_key_modifier_pressed
) {
523 gui_key_modifier_pressed
= 0;
524 if (gui_keysym
== 0) {
525 /* exit/enter grab if pressing Ctrl-Alt */
527 sdl_grab_start(scon
);
528 } else if (!gui_fullscreen
) {
531 /* SDL does not send back all the modifiers key, so we must
539 sdl_process_key(&ev
->key
);
543 static void handle_mousemotion(SDL_Event
*ev
)
546 struct sdl2_state
*scon
= get_scon_from_window(ev
->key
.windowID
);
548 if (qemu_input_is_absolute() || absolute_enabled
) {
550 SDL_GetWindowSize(scon
->real_window
, &scr_w
, &scr_h
);
553 if (gui_grab
&& (ev
->motion
.x
== 0 || ev
->motion
.y
== 0 ||
554 ev
->motion
.x
== max_x
|| ev
->motion
.y
== max_y
)) {
558 (ev
->motion
.x
> 0 && ev
->motion
.x
< max_x
&&
559 ev
->motion
.y
> 0 && ev
->motion
.y
< max_y
)) {
560 sdl_grab_start(scon
);
563 if (gui_grab
|| qemu_input_is_absolute() || absolute_enabled
) {
564 sdl_send_mouse_event(scon
, ev
->motion
.xrel
, ev
->motion
.yrel
, 0,
565 ev
->motion
.x
, ev
->motion
.y
, ev
->motion
.state
);
569 static void handle_mousebutton(SDL_Event
*ev
)
571 int buttonstate
= SDL_GetMouseState(NULL
, NULL
);
572 SDL_MouseButtonEvent
*bev
;
573 struct sdl2_state
*scon
= get_scon_from_window(ev
->key
.windowID
);
577 if (!gui_grab
&& !qemu_input_is_absolute()) {
578 if (ev
->type
== SDL_MOUSEBUTTONUP
&& bev
->button
== SDL_BUTTON_LEFT
) {
579 /* start grabbing all events */
580 sdl_grab_start(scon
);
584 if (ev
->type
== SDL_MOUSEBUTTONDOWN
) {
585 buttonstate
|= SDL_BUTTON(bev
->button
);
587 buttonstate
&= ~SDL_BUTTON(bev
->button
);
589 #ifdef SDL_BUTTON_WHEELUP
590 if (bev
->button
== SDL_BUTTON_WHEELUP
&&
591 ev
->type
== SDL_MOUSEBUTTONDOWN
) {
593 } else if (bev
->button
== SDL_BUTTON_WHEELDOWN
&&
594 ev
->type
== SDL_MOUSEBUTTONDOWN
) {
598 sdl_send_mouse_event(scon
, 0, 0, dz
, bev
->x
, bev
->y
, buttonstate
);
602 static void handle_windowevent(DisplayChangeListener
*dcl
, SDL_Event
*ev
)
605 struct sdl2_state
*scon
= get_scon_from_window(ev
->key
.windowID
);
607 switch (ev
->window
.event
) {
608 case SDL_WINDOWEVENT_RESIZED
:
609 sdl_scale(scon
, ev
->window
.data1
, ev
->window
.data2
);
610 graphic_hw_invalidate(scon
->dcl
.con
);
611 graphic_hw_update(scon
->dcl
.con
);
613 case SDL_WINDOWEVENT_EXPOSED
:
614 SDL_GetWindowSize(SDL_GetWindowFromID(ev
->window
.windowID
), &w
, &h
);
615 sdl_update(dcl
, 0, 0, w
, h
);
617 case SDL_WINDOWEVENT_FOCUS_GAINED
:
618 case SDL_WINDOWEVENT_ENTER
:
619 if (!gui_grab
&& (qemu_input_is_absolute() || absolute_enabled
)) {
620 absolute_mouse_grab(scon
);
623 case SDL_WINDOWEVENT_FOCUS_LOST
:
624 if (gui_grab
&& !gui_fullscreen
) {
628 case SDL_WINDOWEVENT_RESTORED
:
629 update_displaychangelistener(dcl
, GUI_REFRESH_INTERVAL_DEFAULT
);
631 case SDL_WINDOWEVENT_MINIMIZED
:
632 update_displaychangelistener(dcl
, 500);
634 case SDL_WINDOWEVENT_CLOSE
:
637 qemu_system_shutdown_request();
643 static void sdl_refresh(DisplayChangeListener
*dcl
)
645 struct sdl2_state
*scon
= container_of(dcl
, struct sdl2_state
, dcl
);
646 SDL_Event ev1
, *ev
= &ev1
;
648 if (scon
->last_vm_running
!= runstate_is_running()) {
649 scon
->last_vm_running
= runstate_is_running();
650 sdl_update_caption(scon
);
653 graphic_hw_update(dcl
->con
);
655 while (SDL_PollEvent(ev
)) {
666 qemu_system_shutdown_request();
669 case SDL_MOUSEMOTION
:
670 handle_mousemotion(ev
);
672 case SDL_MOUSEBUTTONDOWN
:
673 case SDL_MOUSEBUTTONUP
:
674 handle_mousebutton(ev
);
676 case SDL_WINDOWEVENT
:
677 handle_windowevent(dcl
, ev
);
685 static void sdl_mouse_warp(DisplayChangeListener
*dcl
,
686 int x
, int y
, int on
)
688 struct sdl2_state
*scon
= container_of(dcl
, struct sdl2_state
, dcl
);
693 if (gui_grab
|| qemu_input_is_absolute() || absolute_enabled
) {
694 SDL_SetCursor(guest_sprite
);
695 if (!qemu_input_is_absolute() && !absolute_enabled
) {
696 SDL_WarpMouseInWindow(scon
->real_window
, x
, y
);
699 } else if (gui_grab
) {
703 guest_x
= x
, guest_y
= y
;
706 static void sdl_mouse_define(DisplayChangeListener
*dcl
,
711 SDL_FreeCursor(guest_sprite
);
714 if (guest_sprite_surface
) {
715 SDL_FreeSurface(guest_sprite_surface
);
718 guest_sprite_surface
=
719 SDL_CreateRGBSurfaceFrom(c
->data
, c
->width
, c
->height
, 32, c
->width
* 4,
720 0xff0000, 0x00ff00, 0xff, 0xff000000);
722 if (!guest_sprite_surface
) {
723 fprintf(stderr
, "Failed to make rgb surface from %p\n", c
);
726 guest_sprite
= SDL_CreateColorCursor(guest_sprite_surface
,
729 fprintf(stderr
, "Failed to make color cursor from %p\n", c
);
733 (gui_grab
|| qemu_input_is_absolute() || absolute_enabled
)) {
734 SDL_SetCursor(guest_sprite
);
738 static void sdl_cleanup(void)
741 SDL_FreeCursor(guest_sprite
);
743 SDL_QuitSubSystem(SDL_INIT_VIDEO
);
746 static const DisplayChangeListenerOps dcl_ops
= {
748 .dpy_gfx_update
= sdl_update
,
749 .dpy_gfx_switch
= sdl_switch
,
750 .dpy_refresh
= sdl_refresh
,
751 .dpy_mouse_set
= sdl_mouse_warp
,
752 .dpy_cursor_define
= sdl_mouse_define
,
755 void sdl_display_init(DisplayState
*ds
, int full_screen
, int no_frame
)
767 /* on Linux, SDL may use fbcon|directfb|svgalib when run without
768 * accessible $DISPLAY to open X11 window. This is often the case
769 * when qemu is run using sudo. But in this case, and when actually
770 * run in X11 environment, SDL fights with X11 for the video card,
771 * making current display unavailable, often until reboot.
772 * So make x11 the default SDL video driver if this variable is unset.
773 * This is a bit hackish but saves us from bigger problem.
774 * Maybe it's a good idea to fix this in SDL instead.
776 setenv("SDL_VIDEODRIVER", "x11", 0);
779 flags
= SDL_INIT_VIDEO
| SDL_INIT_NOPARACHUTE
;
780 if (SDL_Init(flags
)) {
781 fprintf(stderr
, "Could not initialize SDL(%s) - exiting\n",
787 QemuConsole
*con
= qemu_console_lookup_by_index(i
);
788 if (!con
|| !qemu_console_is_graphic(con
)) {
792 sdl2_num_outputs
= i
;
793 sdl2_console
= g_new0(struct sdl2_state
, sdl2_num_outputs
);
794 for (i
= 0; i
< sdl2_num_outputs
; i
++) {
795 QemuConsole
*con
= qemu_console_lookup_by_index(i
);
796 sdl2_console
[i
].dcl
.ops
= &dcl_ops
;
797 sdl2_console
[i
].dcl
.con
= con
;
798 register_displaychangelistener(&sdl2_console
[i
].dcl
);
799 sdl2_console
[i
].idx
= i
;
802 /* Load a 32x32x4 image. White pixels are transparent. */
803 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, "qemu-icon.bmp");
805 SDL_Surface
*image
= SDL_LoadBMP(filename
);
807 uint32_t colorkey
= SDL_MapRGB(image
->format
, 255, 255, 255);
808 SDL_SetColorKey(image
, SDL_TRUE
, colorkey
);
809 SDL_SetWindowIcon(sdl2_console
[0].real_window
, image
);
819 mouse_mode_notifier
.notify
= sdl_mouse_mode_change
;
820 qemu_add_mouse_mode_change_notifier(&mouse_mode_notifier
);
824 sdl_cursor_hidden
= SDL_CreateCursor(&data
, &data
, 8, 1, 0, 0);
825 sdl_cursor_normal
= SDL_GetCursor();