From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35192) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQakE-0007Ck-AU for qemu-devel@nongnu.org; Tue, 02 Feb 2016 08:12:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aQajJ-0008Kd-2L for qemu-devel@nongnu.org; Tue, 02 Feb 2016 08:11:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41749) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQajI-0008KB-Pn for qemu-devel@nongnu.org; Tue, 02 Feb 2016 08:10:48 -0500 From: Gerd Hoffmann Date: Tue, 2 Feb 2016 14:10:44 +0100 Message-Id: <1454418644-15153-3-git-send-email-kraxel@redhat.com> In-Reply-To: <1454418644-15153-1-git-send-email-kraxel@redhat.com> References: <1454418644-15153-1-git-send-email-kraxel@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 2/2] sdl: shorten the GUI refresh interval when mouse or keyboard is active List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Jind=C5=99ich=20Makovi=C4=8Dka?= , Gerd Hoffmann From: Jind=C5=99ich Makovi=C4=8Dka Signed-off-by: Jind=C5=99ich Makovi=C4=8Dka Signed-off-by: Gerd Hoffmann --- include/ui/sdl2.h | 1 + ui/sdl.c | 22 ++++++++++++++++++++++ ui/sdl2.c | 23 +++++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/include/ui/sdl2.h b/include/ui/sdl2.h index b7ac38f..3f0b57b 100644 --- a/include/ui/sdl2.h +++ b/include/ui/sdl2.h @@ -19,6 +19,7 @@ struct sdl2_console { int hidden; int opengl; int updates; + int idle_counter; SDL_GLContext winctx; #ifdef CONFIG_OPENGL ConsoleGLState *gls; diff --git a/ui/sdl.c b/ui/sdl.c index c837436..f215fe1 100644 --- a/ui/sdl.c +++ b/ui/sdl.c @@ -60,6 +60,11 @@ static SDL_Cursor *guest_sprite =3D NULL; static SDL_PixelFormat host_format; static int scaling_active =3D 0; 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) =20 #if 0 #define DEBUG_SDL @@ -802,6 +807,7 @@ static void handle_activation(SDL_Event *ev) static void sdl_refresh(DisplayChangeListener *dcl) { SDL_Event ev1, *ev =3D &ev1; + int idle =3D 1; =20 if (last_vm_running !=3D runstate_is_running()) { last_vm_running =3D runstate_is_running(); @@ -817,9 +823,11 @@ static void sdl_refresh(DisplayChangeListener *dcl) sdl_update(dcl, 0, 0, real_screen->w, real_screen->h); break; case SDL_KEYDOWN: + idle =3D 0; handle_keydown(ev); break; case SDL_KEYUP: + idle =3D 0; handle_keyup(ev); break; case SDL_QUIT: @@ -829,10 +837,12 @@ static void sdl_refresh(DisplayChangeListener *dcl) } break; case SDL_MOUSEMOTION: + idle =3D 0; handle_mousemotion(ev); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: + idle =3D 0; handle_mousebutton(ev); break; case SDL_ACTIVEEVENT: @@ -847,6 +857,18 @@ static void sdl_refresh(DisplayChangeListener *dcl) break; } } + + if (idle) { + if (idle_counter < SDL_MAX_IDLE_COUNT) { + idle_counter++; + if (idle_counter >=3D SDL_MAX_IDLE_COUNT) { + dcl->update_interval =3D GUI_REFRESH_INTERVAL_DEFAULT; + } + } + } else { + idle_counter =3D 0; + dcl->update_interval =3D SDL_REFRESH_INTERVAL_BUSY; + } } =20 static void sdl_mouse_warp(DisplayChangeListener *dcl, diff --git a/ui/sdl2.c b/ui/sdl2.c index 46270f4..c0a76d7 100644 --- a/ui/sdl2.c +++ b/ui/sdl2.c @@ -49,6 +49,10 @@ static int guest_x, guest_y; static SDL_Cursor *guest_sprite; static Notifier mouse_mode_notifier; =20 +#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); =20 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) { SDL_Event ev1, *ev =3D &ev1; + int idle =3D 1; =20 if (scon->last_vm_running !=3D runstate_is_running()) { scon->last_vm_running =3D runstate_is_running(); @@ -587,12 +592,15 @@ void sdl2_poll_events(struct sdl2_console *scon) while (SDL_PollEvent(ev)) { switch (ev->type) { case SDL_KEYDOWN: + idle =3D 0; handle_keydown(ev); break; case SDL_KEYUP: + idle =3D 0; handle_keyup(ev); break; case SDL_TEXTINPUT: + idle =3D 0; handle_textinput(ev); break; case SDL_QUIT: @@ -602,13 +610,16 @@ void sdl2_poll_events(struct sdl2_console *scon) } break; case SDL_MOUSEMOTION: + idle =3D 0; handle_mousemotion(ev); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: + idle =3D 0; handle_mousebutton(ev); break; case SDL_MOUSEWHEEL: + idle =3D 0; handle_mousewheel(ev); break; case SDL_WINDOWEVENT: @@ -618,6 +629,18 @@ void sdl2_poll_events(struct sdl2_console *scon) break; } } + + if (idle) { + if (scon->idle_counter < SDL2_MAX_IDLE_COUNT) { + scon->idle_counter++; + if (scon->idle_counter >=3D SDL2_MAX_IDLE_COUNT) { + scon->dcl.update_interval =3D GUI_REFRESH_INTERVAL_DEFAU= LT; + } + } + } else { + scon->idle_counter =3D 0; + scon->dcl.update_interval =3D SDL2_REFRESH_INTERVAL_BUSY; + } } =20 static void sdl_mouse_warp(DisplayChangeListener *dcl, --=20 1.8.3.1