From patchwork Thu Aug 27 10:18:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Lieven X-Patchwork-Id: 511219 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D080D14010F for ; Thu, 27 Aug 2015 20:21:14 +1000 (AEST) Received: from localhost ([::1]:35448 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUuIz-0004Hh-0h for incoming@patchwork.ozlabs.org; Thu, 27 Aug 2015 06:21:13 -0400 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 Received: (qmail 5927 invoked by uid 89); 27 Aug 2015 10:19:12 -0000 Received: from [82.141.1.145] by client-16-kamp (envelope-from , uid 89) with qmail-scanner-2010/03/19-MF (clamdscan: 0.98.7/20842. hbedv: 8.3.34.4/7.12.2.196. spamassassin: 3.4.0. Clear:RC:1(82.141.1.145):SA:0(-1.2/5.0):. Processed in 1.211621 secs); 27 Aug 2015 10:19:12 -0000 Received: from ns.kamp-intra.net (HELO dns.kamp-intra.net) ([82.141.1.145]) by mx01.kamp.de with SMTP; 27 Aug 2015 10:19:09 -0000 X-GL_Whitelist: yes Received: from lieven-pc (lieven-pc.kamp-intra.net [172.21.12.60]) by dns.kamp-intra.net (Postfix) with ESMTP id 7C065E006B; Thu, 27 Aug 2015 12:19:09 +0200 (CEST) Received: by lieven-pc (Postfix, from userid 1000) id 5C0AA20D17; Thu, 27 Aug 2015 12:19:01 +0200 (CEST) From: Peter Lieven To: qemu-devel@nongnu.org Date: Thu, 27 Aug 2015 12:18:54 +0200 Message-Id: <1440670734-5616-5-git-send-email-pl@kamp.de> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1440670734-5616-1-git-send-email-pl@kamp.de> References: <1440670734-5616-1-git-send-email-pl@kamp.de> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a02:248:0:51::16 Cc: Peter Lieven , kraxel@redhat.com Subject: [Qemu-devel] [PATCH 4/4] vnc: destroy server surface if no client is connected X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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);