Received: from eggs.gnu.org ([2001:4830:134:3::10]:58874) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUwZo-0005NQ-2B for qemu-devel@nongnu.org; Thu, 27 Aug 2015 08:46:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZUwZj-00059d-2n for qemu-devel@nongnu.org; Thu, 27 Aug 2015 08:46:44 -0400 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:54778 helo=mx01.kamp.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUwZi-00059E-O9 for qemu-devel@nongnu.org; Thu, 27 Aug 2015 08:46:39 -0400 From: Peter Lieven Date: Thu, 27 Aug 2015 14:46:25 +0200 Message-Id: <1440679585-13984-1-git-send-email-pl@kamp.de> Subject: [Qemu-devel] [PATCH] vnc: allow fall back to RAW encoding List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Lieven , kraxel@redhat.com I have observed that depending on the contents and the encoding it happens that sending data as RAW sometimes would take less space than the encoded data. This is especially the case for small updates or areas with high color images. If sending RAW encoded data is beneficial allow a fall back to RAW encoding for the framebuffer update. Signed-off-by: Peter Lieven --- ui/vnc.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index 57f0e54..5bf2875 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -899,6 +899,8 @@ int vnc_raw_send_framebuffer_update(VncState *vs, int x, int y, int w, int h) int vnc_send_framebuffer_update(VncState *vs, int x, int y, int w, int h) { int n = 0; + bool encode_raw = false; + size_t saved_offs = vs->output.offset; switch(vs->vnc_encoding) { case VNC_ENCODING_ZLIB: @@ -921,10 +923,24 @@ int vnc_send_framebuffer_update(VncState *vs, int x, int y, int w, int h) n = vnc_zywrle_send_framebuffer_update(vs, x, y, w, h); break; default: - vnc_framebuffer_update(vs, x, y, w, h, VNC_ENCODING_RAW); - n = vnc_raw_send_framebuffer_update(vs, x, y, w, h); + encode_raw = true; break; } + + /* If the client has the same pixel format as our internal buffer and + * a RAW encoding would need less space fall back to RAW encoding to + * save bandwidth and processing power in the client. */ + if (!encode_raw && vs->write_pixels == vnc_write_pixels_copy && + 12 + h * w * VNC_SERVER_FB_BYTES <= (vs->output.offset - saved_offs)) { + vs->output.offset = saved_offs; + encode_raw = true; + } + + if (encode_raw) { + vnc_framebuffer_update(vs, x, y, w, h, VNC_ENCODING_RAW); + n = vnc_raw_send_framebuffer_update(vs, x, y, w, h); + } + return n; } -- 1.9.1