diff mbox

[4/4] vnc: destroy server surface if no client is connected

Message ID 1440670734-5616-5-git-send-email-pl@kamp.de
State New
Headers show

Commit Message

Peter Lieven Aug. 27, 2015, 10:18 a.m. UTC
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 <pl@kamp.de>
---
 ui/vnc.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

Comments

Gerd Hoffmann Sept. 3, 2015, 9:57 a.m. UTC | #1
On Do, 2015-08-27 at 12:18 +0200, Peter Lieven wrote:
> 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.

No dummy surface please.  Just set vd->server = NULL.

cheers,
  Gerd
Peter Lieven Sept. 3, 2015, 10:08 a.m. UTC | #2
Am 03.09.2015 um 11:57 schrieb Gerd Hoffmann:
> On Do, 2015-08-27 at 12:18 +0200, Peter Lieven wrote:
>> 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.
> No dummy surface please.  Just set vd->server = NULL.

I can do that, but I have to check for vd->server == NULL at some points then.

Peter
Gerd Hoffmann Sept. 3, 2015, 10:54 a.m. UTC | #3
On Do, 2015-09-03 at 12:08 +0200, Peter Lieven wrote:
> Am 03.09.2015 um 11:57 schrieb Gerd Hoffmann:
> > On Do, 2015-08-27 at 12:18 +0200, Peter Lieven wrote:
> >> 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.
> > No dummy surface please.  Just set vd->server = NULL.
> 
> I can do that, but I have to check for vd->server == NULL at some points then.

Sure.  That'll shortcut code paths which should not have any effect
anyway.  You probably also want factor out server surface initialization
into a function which is called for both first vnc connect and surface
changes.

Oh, and btw: in case the surface changes without resolution/depth
changing (guest page flip) we might simply skip surface
(re-)initialization.

cheers,
  Gerd
diff mbox

Patch

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);