qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Lieven <pl@kamp.de>
To: qemu-devel@nongnu.org
Cc: Peter Lieven <pl@kamp.de>, kraxel@redhat.com
Subject: [Qemu-devel] [PATCH V2] vnc: destroy server surface if no client is connected
Date: Fri, 25 Sep 2015 20:36:57 +0200	[thread overview]
Message-ID: <1443206217-6255-1-git-send-email-pl@kamp.de> (raw)

if no client is connected there is no need to keep the server
surface. Throw it away to save memory.

Signed-off-by: Peter Lieven <pl@kamp.de>
---
v1->v2: don't create a dummy surface just set vd->server = NULL [Gerd]

 ui/vnc.c | 38 +++++++++++++++++++++++++++++++++-----
 1 file changed, 33 insertions(+), 5 deletions(-)

diff --git a/ui/vnc.c b/ui/vnc.c
index eba3fba..8c12ff5 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -630,8 +630,14 @@ static void vnc_dpy_update(DisplayChangeListener *dcl,
 {
     VncDisplay *vd = container_of(dcl, VncDisplay, dcl);
     struct VncSurface *s = &vd->guest;
-    int width = pixman_image_get_width(vd->server);
-    int height = pixman_image_get_height(vd->server);
+    int width, height;
+
+    if (!vd->server) {
+        return;
+    }
+
+    width = pixman_image_get_width(vd->server);
+    height = pixman_image_get_height(vd->server);
 
     vnc_set_area_dirty(s->dirty, width, height, x, y, w, h);
 }
@@ -712,8 +718,17 @@ static void vnc_dpy_switch(DisplayChangeListener *dcl,
 
     vnc_abort_display_jobs(vd);
 
-    /* server surface */
     qemu_pixman_image_unref(vd->server);
+    vd->server = NULL;
+    qemu_pixman_image_unref(vd->guest.fb);
+    vd->guest.fb = NULL;
+
+    /* if no client is connected we don't need a server surface */
+    if (QTAILQ_EMPTY(&vd->clients)) {
+        return;
+    }
+
+    /* server surface */
     vd->ds = surface;
     width = MIN(VNC_MAX_WIDTH, ROUND_UP(surface_width(vd->ds),
                                         VNC_DIRTY_PIXELS_PER_BIT));
@@ -726,7 +741,6 @@ static void vnc_dpy_switch(DisplayChangeListener *dcl,
     if (ds_get_bytes_per_pixel(ds) != vd->guest.ds->pf.bytes_per_pixel)
         console_color_init(ds);
 #endif
-    qemu_pixman_image_unref(vd->guest.fb);
     vd->guest.fb = pixman_image_ref(surface->image);
     vd->guest.format = surface->format;
     memset(vd->guest.dirty, 0x00, sizeof(vd->guest.dirty));
@@ -900,6 +914,10 @@ static void vnc_dpy_copy(DisplayChangeListener *dcl,
     int i, x, y, pitch, inc, w_lim, s;
     int cmp_bytes;
 
+    if (!vd->server) {
+        return;
+    }
+
     vnc_refresh_server_surface(vd);
     QTAILQ_FOREACH_SAFE(vs, &vd->clients, next, vn) {
         if (vnc_has_feature(vs, VNC_FEATURE_COPYRECT)) {
@@ -1213,6 +1231,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);
     }
 
@@ -3049,6 +3070,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;
@@ -3061,9 +3083,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

             reply	other threads:[~2015-09-25 18:37 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-25 18:36 Peter Lieven [this message]
2015-09-29 10:28 ` [Qemu-devel] [PATCH V2] vnc: destroy server surface if no client is connected Gerd Hoffmann
2015-09-29 12:41   ` Peter Lieven
2015-09-29 12:49     ` Gerd Hoffmann
2015-09-29 13:31       ` Peter Lieven
2015-09-29 14:08         ` Gerd Hoffmann
2015-09-29 14:36           ` Peter Lieven
2015-10-01  9:52           ` Peter Lieven
2015-10-02  7:36             ` Gerd Hoffmann
2015-10-02  8:03               ` Peter Lieven
2015-10-02  8:17                 ` Gerd Hoffmann
2015-10-05 15:14               ` Peter Lieven

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=1443206217-6255-1-git-send-email-pl@kamp.de \
    --to=pl@kamp.de \
    --cc=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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;
as well as URLs for NNTP newsgroup(s).