Lines Matching +full:sdl2 +full:- +full:image

31 #include "ui/sdl2.h"
33 #include "system/runstate-action.h"
36 #include "qemu-main.h"
83 if (!scon->surface) { in sdl2_window_create()
86 assert(!scon->real_window); in sdl2_window_create()
93 if (scon->hidden) { in sdl2_window_create()
97 if (scon->opengl) { in sdl2_window_create()
102 scon->real_window = SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED, in sdl2_window_create()
104 surface_width(scon->surface), in sdl2_window_create()
105 surface_height(scon->surface), in sdl2_window_create()
107 if (scon->opengl) { in sdl2_window_create()
110 if (scon->opts->gl == DISPLAY_GL_MODE_ES) { in sdl2_window_create()
117 scon->winctx = SDL_GL_CreateContext(scon->real_window); in sdl2_window_create()
120 /* The SDL renderer is only used by sdl2-2D, when OpenGL is disabled */ in sdl2_window_create()
121 scon->real_renderer = SDL_CreateRenderer(scon->real_window, -1, 0); in sdl2_window_create()
128 if (!scon->real_window) { in sdl2_window_destroy()
132 if (scon->winctx) { in sdl2_window_destroy()
133 SDL_GL_DeleteContext(scon->winctx); in sdl2_window_destroy()
134 scon->winctx = NULL; in sdl2_window_destroy()
136 if (scon->real_renderer) { in sdl2_window_destroy()
137 SDL_DestroyRenderer(scon->real_renderer); in sdl2_window_destroy()
138 scon->real_renderer = NULL; in sdl2_window_destroy()
140 SDL_DestroyWindow(scon->real_window); in sdl2_window_destroy()
141 scon->real_window = NULL; in sdl2_window_destroy()
146 if (!scon->real_window) { in sdl2_window_resize()
150 SDL_SetWindowSize(scon->real_window, in sdl2_window_resize()
151 surface_width(scon->surface), in sdl2_window_resize()
152 surface_height(scon->surface)); in sdl2_window_resize()
157 if (scon->opengl) { in sdl2_redraw()
177 status = " - Press ⌃⌥⇧G to exit grab"; in sdl_update_caption()
179 status = " - Press Ctrl-Alt-Shift-G to exit grab"; in sdl_update_caption()
182 status = " - Press Right-Ctrl-G to exit grab"; in sdl_update_caption()
185 status = " - Press ⌃⌥G to exit grab"; in sdl_update_caption()
187 status = " - Press Ctrl-Alt-G to exit grab"; in sdl_update_caption()
193 snprintf(win_title, sizeof(win_title), "QEMU (%s-%d)%s", qemu_name, in sdl_update_caption()
194 scon->idx, status); in sdl_update_caption()
201 if (scon->real_window) { in sdl_update_caption()
202 SDL_SetWindowTitle(scon->real_window, win_title); in sdl_update_caption()
208 if (scon->opts->has_show_cursor && scon->opts->show_cursor) { in sdl_hide_cursor()
215 if (!qemu_input_is_absolute(scon->dcl.con)) { in sdl_hide_cursor()
222 if (scon->opts->has_show_cursor && scon->opts->show_cursor) { in sdl_show_cursor()
226 if (!qemu_input_is_absolute(scon->dcl.con)) { in sdl_show_cursor()
231 (gui_grab || qemu_input_is_absolute(scon->dcl.con) || absolute_enabled)) { in sdl_show_cursor()
242 QemuConsole *con = scon ? scon->dcl.con : NULL; in sdl_grab_start()
252 if (!(SDL_GetWindowFlags(scon->real_window) & SDL_WINDOW_INPUT_FOCUS)) { in sdl_grab_start()
257 if (!qemu_input_is_absolute(scon->dcl.con) && !absolute_enabled) { in sdl_grab_start()
258 SDL_WarpMouseInWindow(scon->real_window, guest_x, guest_y); in sdl_grab_start()
263 SDL_SetWindowGrab(scon->real_window, SDL_TRUE); in sdl_grab_start()
270 SDL_SetWindowGrab(scon->real_window, SDL_FALSE); in sdl_grab_end()
281 SDL_GetWindowSize(scon->real_window, &scr_w, &scr_h); in absolute_mouse_grab()
282 if (mouse_x > 0 && mouse_x < scr_w - 1 && in absolute_mouse_grab()
283 mouse_y > 0 && mouse_y < scr_h - 1) { in absolute_mouse_grab()
317 qemu_input_update_buttons(scon->dcl.con, bmap, prev_state, state); in sdl_send_mouse_event()
321 if (qemu_input_is_absolute(scon->dcl.con)) { in sdl_send_mouse_event()
322 qemu_input_queue_abs(scon->dcl.con, INPUT_AXIS_X, in sdl_send_mouse_event()
323 x, 0, surface_width(scon->surface)); in sdl_send_mouse_event()
324 qemu_input_queue_abs(scon->dcl.con, INPUT_AXIS_Y, in sdl_send_mouse_event()
325 y, 0, surface_height(scon->surface)); in sdl_send_mouse_event()
328 x -= guest_x; in sdl_send_mouse_event()
329 y -= guest_y; in sdl_send_mouse_event()
335 qemu_input_queue_rel(scon->dcl.con, INPUT_AXIS_X, dx); in sdl_send_mouse_event()
336 qemu_input_queue_rel(scon->dcl.con, INPUT_AXIS_Y, dy); in sdl_send_mouse_event()
345 SDL_SetWindowFullscreen(scon->real_window, in toggle_full_screen()
353 SDL_SetWindowFullscreen(scon->real_window, 0); in toggle_full_screen()
375 struct sdl2_console *scon = get_scon_from_window(ev->key.windowID); in handle_keydown()
382 scon->gui_keysym = false; in handle_keydown()
384 if (!scon->ignore_hotkeys && gui_key_modifier_pressed && !ev->key.repeat) { in handle_keydown()
385 switch (ev->key.keysym.scancode) { in handle_keydown()
398 win = ev->key.keysym.scancode - SDL_SCANCODE_1; in handle_keydown()
409 scon->gui_keysym = true; in handle_keydown()
414 scon->gui_keysym = true; in handle_keydown()
417 scon->gui_keysym = true; in handle_keydown()
426 if (!scon->opengl) { in handle_keydown()
427 /* re-create scon->texture */ in handle_keydown()
428 sdl2_2d_switch(&scon->dcl, scon->surface); in handle_keydown()
430 scon->gui_keysym = true; in handle_keydown()
438 SDL_GetWindowSize(scon->real_window, &scr_w, &scr_h); in handle_keydown()
440 width = MAX(scr_w + (ev->key.keysym.scancode == in handle_keydown()
441 SDL_SCANCODE_KP_PLUS ? 50 : -50), in handle_keydown()
443 height = (surface_height(scon->surface) * width) / in handle_keydown()
444 surface_width(scon->surface); in handle_keydown()
449 scon->gui_keysym = true; in handle_keydown()
456 if (!scon->gui_keysym) { in handle_keydown()
457 sdl2_process_key(scon, &ev->key); in handle_keydown()
463 struct sdl2_console *scon = get_scon_from_window(ev->key.windowID); in handle_keyup()
469 scon->ignore_hotkeys = false; in handle_keyup()
470 sdl2_process_key(scon, &ev->key); in handle_keyup()
475 struct sdl2_console *scon = get_scon_from_window(ev->text.windowID); in handle_textinput()
476 QemuConsole *con = scon ? scon->dcl.con : NULL; in handle_textinput()
482 if (!scon->gui_keysym && QEMU_IS_TEXT_CONSOLE(con)) { in handle_textinput()
483 qemu_text_console_put_string(QEMU_TEXT_CONSOLE(con), ev->text.text, strlen(ev->text.text)); in handle_textinput()
490 struct sdl2_console *scon = get_scon_from_window(ev->motion.windowID); in handle_mousemotion()
493 if (!scon || !qemu_console_is_graphic(scon->dcl.con)) { in handle_mousemotion()
497 SDL_GetWindowSize(scon->real_window, &scr_w, &scr_h); in handle_mousemotion()
498 if (qemu_input_is_absolute(scon->dcl.con) || absolute_enabled) { in handle_mousemotion()
499 max_x = scr_w - 1; in handle_mousemotion()
500 max_y = scr_h - 1; in handle_mousemotion()
502 && (ev->motion.x == 0 || ev->motion.y == 0 || in handle_mousemotion()
503 ev->motion.x == max_x || ev->motion.y == max_y)) { in handle_mousemotion()
507 (ev->motion.x > 0 && ev->motion.x < max_x && in handle_mousemotion()
508 ev->motion.y > 0 && ev->motion.y < max_y)) { in handle_mousemotion()
512 surf_w = surface_width(scon->surface); in handle_mousemotion()
513 surf_h = surface_height(scon->surface); in handle_mousemotion()
514 x = (int64_t)ev->motion.x * surf_w / scr_w; in handle_mousemotion()
515 y = (int64_t)ev->motion.y * surf_h / scr_h; in handle_mousemotion()
516 dx = (int64_t)ev->motion.xrel * surf_w / scr_w; in handle_mousemotion()
517 dy = (int64_t)ev->motion.yrel * surf_h / scr_h; in handle_mousemotion()
518 if (gui_grab || qemu_input_is_absolute(scon->dcl.con) || absolute_enabled) { in handle_mousemotion()
519 sdl_send_mouse_event(scon, dx, dy, x, y, ev->motion.state); in handle_mousemotion()
527 struct sdl2_console *scon = get_scon_from_window(ev->button.windowID); in handle_mousebutton()
530 if (!scon || !qemu_console_is_graphic(scon->dcl.con)) { in handle_mousebutton()
534 bev = &ev->button; in handle_mousebutton()
535 SDL_GetWindowSize(scon->real_window, &scr_w, &scr_h); in handle_mousebutton()
536 x = (int64_t)bev->x * surface_width(scon->surface) / scr_w; in handle_mousebutton()
537 y = (int64_t)bev->y * surface_height(scon->surface) / scr_h; in handle_mousebutton()
539 if (!gui_grab && !qemu_input_is_absolute(scon->dcl.con)) { in handle_mousebutton()
540 if (ev->type == SDL_MOUSEBUTTONUP && bev->button == SDL_BUTTON_LEFT) { in handle_mousebutton()
545 if (ev->type == SDL_MOUSEBUTTONDOWN) { in handle_mousebutton()
546 buttonstate |= SDL_BUTTON(bev->button); in handle_mousebutton()
548 buttonstate &= ~SDL_BUTTON(bev->button); in handle_mousebutton()
556 struct sdl2_console *scon = get_scon_from_window(ev->wheel.windowID); in handle_mousewheel()
557 SDL_MouseWheelEvent *wev = &ev->wheel; in handle_mousewheel()
560 if (!scon || !qemu_console_is_graphic(scon->dcl.con)) { in handle_mousewheel()
564 if (wev->y > 0) { in handle_mousewheel()
566 } else if (wev->y < 0) { in handle_mousewheel()
568 } else if (wev->x < 0) { in handle_mousewheel()
570 } else if (wev->x > 0) { in handle_mousewheel()
576 qemu_input_queue_btn(scon->dcl.con, btn, true); in handle_mousewheel()
578 qemu_input_queue_btn(scon->dcl.con, btn, false); in handle_mousewheel()
584 struct sdl2_console *scon = get_scon_from_window(ev->window.windowID); in handle_windowevent()
591 switch (ev->window.event) { in handle_windowevent()
596 info.width = ev->window.data1; in handle_windowevent()
597 info.height = ev->window.data2; in handle_windowevent()
598 dpy_set_ui_info(scon->dcl.con, &info, true); in handle_windowevent()
608 if (!gui_grab && (qemu_input_is_absolute(scon->dcl.con) || absolute_enabled)) { in handle_windowevent()
618 scon->ignore_hotkeys = get_mod_state(); in handle_windowevent()
626 update_displaychangelistener(&scon->dcl, GUI_REFRESH_INTERVAL_DEFAULT); in handle_windowevent()
629 update_displaychangelistener(&scon->dcl, 500); in handle_windowevent()
632 if (qemu_console_is_graphic(scon->dcl.con)) { in handle_windowevent()
633 if (scon->opts->has_window_close && !scon->opts->window_close) { in handle_windowevent()
641 SDL_HideWindow(scon->real_window); in handle_windowevent()
642 scon->hidden = true; in handle_windowevent()
646 scon->hidden = false; in handle_windowevent()
649 scon->hidden = true; in handle_windowevent()
660 if (scon->last_vm_running != runstate_is_running()) { in sdl2_poll_events()
661 scon->last_vm_running = runstate_is_running(); in sdl2_poll_events()
666 switch (ev->type) { in sdl2_poll_events()
680 if (scon->opts->has_window_close && !scon->opts->window_close) { in sdl2_poll_events()
710 if (scon->idle_counter < SDL2_MAX_IDLE_COUNT) { in sdl2_poll_events()
711 scon->idle_counter++; in sdl2_poll_events()
712 if (scon->idle_counter >= SDL2_MAX_IDLE_COUNT) { in sdl2_poll_events()
713 scon->dcl.update_interval = GUI_REFRESH_INTERVAL_DEFAULT; in sdl2_poll_events()
717 scon->idle_counter = 0; in sdl2_poll_events()
718 scon->dcl.update_interval = SDL2_REFRESH_INTERVAL_BUSY; in sdl2_poll_events()
727 if (!qemu_console_is_graphic(scon->dcl.con)) { in sdl_mouse_warp()
735 if (gui_grab || qemu_input_is_absolute(scon->dcl.con) || absolute_enabled) { in sdl_mouse_warp()
737 if (!qemu_input_is_absolute(scon->dcl.con) && !absolute_enabled) { in sdl_mouse_warp()
738 SDL_WarpMouseInWindow(scon->real_window, x, y); in sdl_mouse_warp()
761 SDL_CreateRGBSurfaceFrom(c->data, c->width, c->height, 32, c->width * 4, in sdl_mouse_define()
769 c->hot_x, c->hot_y); in sdl_mouse_define()
775 (gui_grab || qemu_input_is_absolute(dcl->con) || absolute_enabled)) { in sdl_mouse_define()
789 .dpy_name = "sdl2-2d",
800 .dpy_name = "sdl2-gl",
817 return dcl->ops == &dcl_gl_ops; in sdl2_gl_is_compatible_dcl()
830 assert(o->type == DISPLAY_TYPE_SDL); in sdl2_display_early_init()
831 if (o->has_gl && o->gl) { in sdl2_display_early_init()
846 assert(o->type == DISPLAY_TYPE_SDL); in sdl2_display_init()
853 fprintf(stderr, "Could not initialize SDL(%s) - exiting\n", in sdl2_display_init()
869 gui_fullscreen = o->has_full_screen && o->full_screen; in sdl2_display_init()
871 if (o->u.sdl.has_grab_mod) { in sdl2_display_init()
872 if (o->u.sdl.grab_mod == HOT_KEY_MOD_LSHIFT_LCTRL_LALT) { in sdl2_display_init()
874 } else if (o->u.sdl.grab_mod == HOT_KEY_MOD_RCTRL) { in sdl2_display_init()
929 /* Load a 32x32x4 image. White pixels are transparent. */ in sdl2_display_init()
933 uint32_t colorkey = SDL_MapRGB(icon->format, 255, 255, 255); in sdl2_display_init()
972 module_dep("ui-opengl");