[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 4/4] vnc: destroy server surface if no client is con
From: |
Peter Lieven |
Subject: |
[Qemu-devel] [PATCH 4/4] vnc: destroy server surface if no client is connected |
Date: |
Thu, 27 Aug 2015 12:18:54 +0200 |
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 <address@hidden>
---
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