sdl: shorten the GUI refresh interval when mouse or keyboard is active

Signed-off-by: Jindřich Makovička <makovick@gmail.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
Jindřich Makovička 2016-01-12 20:18:24 +01:00 committed by Gerd Hoffmann
parent 919e11f373
commit 56bdd4b69a
3 changed files with 46 additions and 0 deletions

View File

@ -19,6 +19,7 @@ struct sdl2_console {
int hidden; int hidden;
int opengl; int opengl;
int updates; int updates;
int idle_counter;
SDL_GLContext winctx; SDL_GLContext winctx;
#ifdef CONFIG_OPENGL #ifdef CONFIG_OPENGL
ConsoleGLState *gls; ConsoleGLState *gls;

View File

@ -60,6 +60,11 @@ static SDL_Cursor *guest_sprite = NULL;
static SDL_PixelFormat host_format; static SDL_PixelFormat host_format;
static int scaling_active = 0; static int scaling_active = 0;
static Notifier mouse_mode_notifier; static Notifier mouse_mode_notifier;
static int idle_counter;
#define SDL_REFRESH_INTERVAL_BUSY 10
#define SDL_MAX_IDLE_COUNT (2 * GUI_REFRESH_INTERVAL_DEFAULT \
/ SDL_REFRESH_INTERVAL_BUSY + 1)
#if 0 #if 0
#define DEBUG_SDL #define DEBUG_SDL
@ -802,6 +807,7 @@ static void handle_activation(SDL_Event *ev)
static void sdl_refresh(DisplayChangeListener *dcl) static void sdl_refresh(DisplayChangeListener *dcl)
{ {
SDL_Event ev1, *ev = &ev1; SDL_Event ev1, *ev = &ev1;
int idle = 1;
if (last_vm_running != runstate_is_running()) { if (last_vm_running != runstate_is_running()) {
last_vm_running = runstate_is_running(); last_vm_running = runstate_is_running();
@ -817,9 +823,11 @@ static void sdl_refresh(DisplayChangeListener *dcl)
sdl_update(dcl, 0, 0, real_screen->w, real_screen->h); sdl_update(dcl, 0, 0, real_screen->w, real_screen->h);
break; break;
case SDL_KEYDOWN: case SDL_KEYDOWN:
idle = 0;
handle_keydown(ev); handle_keydown(ev);
break; break;
case SDL_KEYUP: case SDL_KEYUP:
idle = 0;
handle_keyup(ev); handle_keyup(ev);
break; break;
case SDL_QUIT: case SDL_QUIT:
@ -829,10 +837,12 @@ static void sdl_refresh(DisplayChangeListener *dcl)
} }
break; break;
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
idle = 0;
handle_mousemotion(ev); handle_mousemotion(ev);
break; break;
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
idle = 0;
handle_mousebutton(ev); handle_mousebutton(ev);
break; break;
case SDL_ACTIVEEVENT: case SDL_ACTIVEEVENT:
@ -847,6 +857,18 @@ static void sdl_refresh(DisplayChangeListener *dcl)
break; break;
} }
} }
if (idle) {
if (idle_counter < SDL_MAX_IDLE_COUNT) {
idle_counter++;
if (idle_counter >= SDL_MAX_IDLE_COUNT) {
dcl->update_interval = GUI_REFRESH_INTERVAL_DEFAULT;
}
}
} else {
idle_counter = 0;
dcl->update_interval = SDL_REFRESH_INTERVAL_BUSY;
}
} }
static void sdl_mouse_warp(DisplayChangeListener *dcl, static void sdl_mouse_warp(DisplayChangeListener *dcl,

View File

@ -49,6 +49,10 @@ static int guest_x, guest_y;
static SDL_Cursor *guest_sprite; static SDL_Cursor *guest_sprite;
static Notifier mouse_mode_notifier; static Notifier mouse_mode_notifier;
#define SDL2_REFRESH_INTERVAL_BUSY 10
#define SDL2_MAX_IDLE_COUNT (2 * GUI_REFRESH_INTERVAL_DEFAULT \
/ SDL2_REFRESH_INTERVAL_BUSY + 1)
static void sdl_update_caption(struct sdl2_console *scon); static void sdl_update_caption(struct sdl2_console *scon);
static struct sdl2_console *get_scon_from_window(uint32_t window_id) static struct sdl2_console *get_scon_from_window(uint32_t window_id)
@ -578,6 +582,7 @@ static void handle_windowevent(SDL_Event *ev)
void sdl2_poll_events(struct sdl2_console *scon) void sdl2_poll_events(struct sdl2_console *scon)
{ {
SDL_Event ev1, *ev = &ev1; SDL_Event ev1, *ev = &ev1;
int idle = 1;
if (scon->last_vm_running != runstate_is_running()) { if (scon->last_vm_running != runstate_is_running()) {
scon->last_vm_running = runstate_is_running(); scon->last_vm_running = runstate_is_running();
@ -587,12 +592,15 @@ void sdl2_poll_events(struct sdl2_console *scon)
while (SDL_PollEvent(ev)) { while (SDL_PollEvent(ev)) {
switch (ev->type) { switch (ev->type) {
case SDL_KEYDOWN: case SDL_KEYDOWN:
idle = 0;
handle_keydown(ev); handle_keydown(ev);
break; break;
case SDL_KEYUP: case SDL_KEYUP:
idle = 0;
handle_keyup(ev); handle_keyup(ev);
break; break;
case SDL_TEXTINPUT: case SDL_TEXTINPUT:
idle = 0;
handle_textinput(ev); handle_textinput(ev);
break; break;
case SDL_QUIT: case SDL_QUIT:
@ -602,13 +610,16 @@ void sdl2_poll_events(struct sdl2_console *scon)
} }
break; break;
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
idle = 0;
handle_mousemotion(ev); handle_mousemotion(ev);
break; break;
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
idle = 0;
handle_mousebutton(ev); handle_mousebutton(ev);
break; break;
case SDL_MOUSEWHEEL: case SDL_MOUSEWHEEL:
idle = 0;
handle_mousewheel(ev); handle_mousewheel(ev);
break; break;
case SDL_WINDOWEVENT: case SDL_WINDOWEVENT:
@ -618,6 +629,18 @@ void sdl2_poll_events(struct sdl2_console *scon)
break; break;
} }
} }
if (idle) {
if (scon->idle_counter < SDL2_MAX_IDLE_COUNT) {
scon->idle_counter++;
if (scon->idle_counter >= SDL2_MAX_IDLE_COUNT) {
scon->dcl.update_interval = GUI_REFRESH_INTERVAL_DEFAULT;
}
}
} else {
scon->idle_counter = 0;
scon->dcl.update_interval = SDL2_REFRESH_INTERVAL_BUSY;
}
} }
static void sdl_mouse_warp(DisplayChangeListener *dcl, static void sdl_mouse_warp(DisplayChangeListener *dcl,