public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Pekka Enberg <penberg@kernel.org>
To: kvm@vger.kernel.org
Cc: Pekka Enberg <penberg@kernel.org>,
	Cyrill Gorcunov <gorcunov@gmail.com>, Ingo Molnar <mingo@elte.hu>,
	John Floren <john@jfloren.net>,
	Sasha Levin <levinsasha928@gmail.com>
Subject: [PATCH] kvm tools, ui: Optimize SDL updates
Date: Sat,  4 Jun 2011 00:20:23 +0300	[thread overview]
Message-ID: <1307136023-16693-1-git-send-email-penberg@kernel.org> (raw)

This patch optimizes SDL updates by keeping track of which parts of the guest
screen have been written since last update and calling SDL_BlitSurface() and
SDL_UpdateRect() for only changed parts of the screen.

Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: John Floren <john@jfloren.net>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
---
 tools/kvm/ui/sdl.c |   60 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 57 insertions(+), 3 deletions(-)

diff --git a/tools/kvm/ui/sdl.c b/tools/kvm/ui/sdl.c
index bc69ed9..f175a60 100644
--- a/tools/kvm/ui/sdl.c
+++ b/tools/kvm/ui/sdl.c
@@ -6,11 +6,51 @@
 #include <SDL/SDL.h>
 #include <pthread.h>
 
+#include <linux/kernel.h>
+
 #define FRAME_RATE		25
 
+static u64 min_x;
+static u64 min_y;
+static u64 max_x;
+static u64 max_y;
+
+static void sdl__finish(void)
+{
+	max_x = 0;
+	max_y = 0;
+	min_x = ULLONG_MAX;
+	min_y = ULLONG_MAX;
+}
+
+static inline bool sdl__need_update(void)
+{
+	return min_x < max_x && min_y < max_y;
+}
+
 static void sdl__write(struct framebuffer *fb, u64 addr, u8 *data, u32 len)
 {
-	memcpy(&fb->mem[addr - fb->mem_addr], data, len);
+	u64 x, y;
+	u64 pos;
+
+	pos = addr - fb->mem_addr;
+
+	x = (pos / 4) % fb->width;
+	y = ((pos / 4) - x) / fb->width;
+
+	if (x < min_x)
+		min_x = x;
+
+	if (y < min_y)
+		min_y = y;
+
+	if (x > max_x)
+		max_x = x;
+
+	if (y > max_y)
+		max_y = y;
+
+	memcpy(&fb->mem[pos], data, len);
 }
 
 static void *sdl__thread(void *p)
@@ -40,9 +80,23 @@ static void *sdl__thread(void *p)
 	if (!screen)
 		die("Unable to set SDL video mode");
 
+	sdl__finish();
+
 	for (;;) {
-		SDL_BlitSurface(guest_screen, NULL, screen, NULL);
-		SDL_UpdateRect(screen, 0, 0, 0, 0);
+		if (sdl__need_update()) {
+			SDL_Rect rect = {
+				.x		= min_x,
+				.y		= min_y,
+				.w		= max_x - min_x,
+				.h		= max_y - min_y,
+			};
+
+			SDL_BlitSurface(guest_screen, &rect, screen, &rect);
+			SDL_UpdateRect(screen, rect.x, rect.y, rect.w, rect.h);
+		}
+
+		sdl__finish();
+
 		while (SDL_PollEvent(&ev)) {
 			switch (ev.type) {
 			case SDL_QUIT:
-- 
1.7.0.4


             reply	other threads:[~2011-06-03 21:20 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-03 21:20 Pekka Enberg [this message]
2011-06-04  9:54 ` [PATCH] kvm tools, ui: Optimize SDL updates Ingo Molnar
2011-06-04 10:27   ` Alexander Graf
2011-06-04 10:42     ` Ingo Molnar
2011-06-04 10:46       ` Alexander Graf
2011-06-04 10:54         ` Ingo Molnar
2011-06-04 11:07           ` Alexander Graf
2011-06-04 11:53             ` Ingo Molnar
2011-06-04 11:59               ` Alexander Graf
2011-06-04 12:04               ` Sasha Levin
2011-06-04 13:48                 ` Alexander Graf
2011-06-04 14:19                   ` Sasha Levin
2011-06-04 15:21                     ` Alexander Graf
2011-06-04 15:34                       ` Sasha Levin
2011-06-04 15:40                         ` Alexander Graf
2011-06-04 16:49                           ` Sasha Levin
2011-06-05  8:41                             ` Alexander Graf
2011-06-05  9:32             ` Alon Levy
2011-06-06  7:02             ` Gerd Hoffmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1307136023-16693-1-git-send-email-penberg@kernel.org \
    --to=penberg@kernel.org \
    --cc=gorcunov@gmail.com \
    --cc=john@jfloren.net \
    --cc=kvm@vger.kernel.org \
    --cc=levinsasha928@gmail.com \
    --cc=mingo@elte.hu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox