From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39848) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUuH8-0001kP-8Q for qemu-devel@nongnu.org; Thu, 27 Aug 2015 06:19:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZUuH4-0000zQ-N5 for qemu-devel@nongnu.org; Thu, 27 Aug 2015 06:19:18 -0400 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:42236 helo=mx01.kamp.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUuH4-0000xM-2G for qemu-devel@nongnu.org; Thu, 27 Aug 2015 06:19:14 -0400 From: Peter Lieven Date: Thu, 27 Aug 2015 12:18:54 +0200 Message-Id: <1440670734-5616-5-git-send-email-pl@kamp.de> In-Reply-To: <1440670734-5616-1-git-send-email-pl@kamp.de> References: <1440670734-5616-1-git-send-email-pl@kamp.de> Subject: [Qemu-devel] [PATCH 4/4] vnc: destroy server surface if no client is connected List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Lieven , kraxel@redhat.com if no client is connected there is no need to keep the server surface. Throw it away and replace it with a dummy surface to save memory. Signed-off-by: Peter Lieven --- ui/vnc.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ui/vnc.c b/ui/vnc.c index 061e337..57f0e54 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -776,6 +776,11 @@ static void vnc_dpy_switch(DisplayChangeListener *dcl, vnc_abort_display_jobs(vd); + /* if no client is connected use a dummy surface */ + if (QTAILQ_EMPTY(&vd->clients)) { + surface = qemu_create_displaysurface(0, 0); + } + /* server surface */ qemu_pixman_image_unref(vd->server); vd->ds = surface; @@ -1263,6 +1268,9 @@ void vnc_disconnect_finish(VncState *vs) if (vs->initialized) { QTAILQ_REMOVE(&vs->vd->clients, vs, next); + if (QTAILQ_EMPTY(&vs->vd->clients)) { + vnc_dpy_switch(&vs->vd->dcl, NULL); + } qemu_remove_mouse_mode_change_notifier(&vs->mouse_mode_notifier); } @@ -3083,6 +3091,7 @@ void vnc_init_state(VncState *vs) { vs->initialized = true; VncDisplay *vd = vs->vd; + bool first_client; vs->last_x = -1; vs->last_y = -1; @@ -3095,9 +3104,15 @@ void vnc_init_state(VncState *vs) qemu_mutex_init(&vs->output_mutex); vs->bh = qemu_bh_new(vnc_jobs_bh, vs); + first_client = QTAILQ_EMPTY(&vd->clients); QTAILQ_INSERT_TAIL(&vd->clients, vs, next); - graphic_hw_update(vd->dcl.con); + if (first_client) { + /* set/restore the correct surface in the VNC server */ + console_select(0); + } else { + graphic_hw_update(vd->dcl.con); + } vnc_write(vs, "RFB 003.008\n", 12); vnc_flush(vs); -- 1.9.1