From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LRVSQ-0003Fj-3f for qemu-devel@nongnu.org; Mon, 26 Jan 2009 12:41:10 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LRVSK-00037i-51 for qemu-devel@nongnu.org; Mon, 26 Jan 2009 12:41:07 -0500 Received: from [199.232.76.173] (port=36632 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LRVSJ-00036S-DO for qemu-devel@nongnu.org; Mon, 26 Jan 2009 12:41:03 -0500 Received: from mx20.gnu.org ([199.232.41.8]:51743) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LRV2c-0003jM-Vw for qemu-devel@nongnu.org; Mon, 26 Jan 2009 12:14:31 -0500 Received: from e5.ny.us.ibm.com ([32.97.182.145]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LRTdw-0007eG-Gs for qemu-devel@nongnu.org; Mon, 26 Jan 2009 10:44:56 -0500 Received: from d01relay02.pok.ibm.com (d01relay02.pok.ibm.com [9.56.227.234]) by e5.ny.us.ibm.com (8.13.1/8.13.1) with ESMTP id n0QFa2nO003654 for ; Mon, 26 Jan 2009 10:36:02 -0500 Received: from d01av01.pok.ibm.com (d01av01.pok.ibm.com [9.56.224.215]) by d01relay02.pok.ibm.com (8.13.8/8.13.8/NCO v9.1) with ESMTP id n0QFc18f178442 for ; Mon, 26 Jan 2009 10:38:01 -0500 Received: from d01av01.pok.ibm.com (loopback [127.0.0.1]) by d01av01.pok.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id n0QFc1so003680 for ; Mon, 26 Jan 2009 10:38:01 -0500 Received: from squirrel.codemonkey.ws (sig-9-65-32-74.mts.ibm.com [9.65.32.74]) by d01av01.pok.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id n0QFc0GV003637 for ; Mon, 26 Jan 2009 10:38:01 -0500 Message-ID: <497DD8CC.6060201@us.ibm.com> Date: Mon, 26 Jan 2009 09:37:48 -0600 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] vnc fixes and improvements References: <497A1173.30408@eu.citrix.com> In-Reply-To: <497A1173.30408@eu.citrix.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Stefano Stabellini wrote: > Hi all, > this patch fixes a bug and improves the generic pixel conversion > function in vnc.c. > The bug is that when a new vnc client connects we need to reset the flag > has_WMVi but currently we don't. > The generic pixel conversion function is vnc_convert_pixel and currently > is not very efficient since uses the division and multiplication > operators. > To make it more efficient I changed to use bit shift operators instead. > > Signed-off-by: Stefano Stabellini > Applied. Thanks. Regards, Anthony Liguori > diff --git a/console.c b/console.c > index 4bcdac1..68ac970 100644 > --- a/console.c > +++ b/console.c > @@ -1470,6 +1470,9 @@ PixelFormat qemu_different_endianness_pixelformat(int bpp) > pf.rshift = 0; > pf.gshift = 8; > pf.bshift = 16; > + pf.rbits = 8; > + pf.gbits = 8; > + pf.bbits = 8; > break; > case 32: > pf.rmask = 0x0000FF00; > @@ -1484,6 +1487,10 @@ PixelFormat qemu_different_endianness_pixelformat(int bpp) > pf.rshift = 8; > pf.gshift = 16; > pf.bshift = 24; > + pf.rbits = 8; > + pf.gbits = 8; > + pf.bbits = 8; > + pf.abits = 8; > break; > default: > break; > @@ -1512,6 +1519,9 @@ PixelFormat qemu_default_pixelformat(int bpp) > pf.rshift = 11; > pf.gshift = 5; > pf.bshift = 0; > + pf.rbits = 5; > + pf.gbits = 6; > + pf.bbits = 5; > break; > case 24: > pf.rmask = 0x00FF0000; > @@ -1523,6 +1533,9 @@ PixelFormat qemu_default_pixelformat(int bpp) > pf.rshift = 16; > pf.gshift = 8; > pf.bshift = 0; > + pf.rbits = 8; > + pf.gbits = 8; > + pf.bbits = 8; > case 32: > pf.rmask = 0x00FF0000; > pf.gmask = 0x0000FF00; > @@ -1535,6 +1548,10 @@ PixelFormat qemu_default_pixelformat(int bpp) > pf.rshift = 16; > pf.gshift = 8; > pf.bshift = 0; > + pf.rbits = 8; > + pf.gbits = 8; > + pf.bbits = 8; > + pf.abits = 8; > break; > default: > break; > diff --git a/console.h b/console.h > index 6e764b3..4a2f06f 100644 > --- a/console.h > +++ b/console.h > @@ -83,6 +83,7 @@ struct PixelFormat { > uint32_t rmask, gmask, bmask, amask; > uint8_t rshift, gshift, bshift, ashift; > uint8_t rmax, gmax, bmax, amax; > + uint8_t rbits, gbits, bbits, abits; > }; > > struct DisplaySurface { > diff --git a/vnc.c b/vnc.c > index 17ea9a2..2b3a6eb 100644 > --- a/vnc.c > +++ b/vnc.c > @@ -56,6 +56,12 @@ static void vnc_debug_gnutls_log(int level, const char* str) { > #define VNC_DEBUG(fmt, ...) do { } while (0) > #endif > > +#define count_bits(c, v) { \ > + for (c = 0; v; v >>= 1) \ > + { \ > + c += v & 1; \ > + } \ > +} > > typedef struct Buffer > { > @@ -329,12 +335,12 @@ static void vnc_convert_pixel(VncState *vs, uint8_t *buf, uint32_t v) > { > uint8_t r, g, b; > > - r = ((v >> vs->serverds.pf.rshift) & vs->serverds.pf.rmax) * (vs->clientds.pf.rmax + 1) / > - (vs->serverds.pf.rmax + 1); > - g = ((v >> vs->serverds.pf.gshift) & vs->serverds.pf.gmax) * (vs->clientds.pf.gmax + 1) / > - (vs->serverds.pf.gmax + 1); > - b = ((v >> vs->serverds.pf.bshift) & vs->serverds.pf.bmax) * (vs->clientds.pf.bmax + 1) / > - (vs->serverds.pf.bmax + 1); > + r = ((((v & vs->serverds.pf.rmask) >> vs->serverds.pf.rshift) << vs->clientds.pf.rbits) >> > + vs->serverds.pf.rbits); > + g = ((((v & vs->serverds.pf.gmask) >> vs->serverds.pf.gshift) << vs->clientds.pf.gbits) >> > + vs->serverds.pf.gbits); > + b = ((((v & vs->serverds.pf.bmask) >> vs->serverds.pf.bshift) << vs->clientds.pf.bbits) >> > + vs->serverds.pf.bbits); > v = (r << vs->clientds.pf.rshift) | > (g << vs->clientds.pf.gshift) | > (b << vs->clientds.pf.bshift); > @@ -1272,12 +1278,15 @@ static void set_pixel_format(VncState *vs, > > vs->clientds = vs->serverds; > vs->clientds.pf.rmax = red_max; > + count_bits(vs->clientds.pf.rbits, red_max); > vs->clientds.pf.rshift = red_shift; > vs->clientds.pf.rmask = red_max << red_shift; > vs->clientds.pf.gmax = green_max; > + count_bits(vs->clientds.pf.gbits, green_max); > vs->clientds.pf.gshift = green_shift; > vs->clientds.pf.gmask = green_max << green_shift; > vs->clientds.pf.bmax = blue_max; > + count_bits(vs->clientds.pf.bbits, blue_max); > vs->clientds.pf.bshift = blue_shift; > vs->clientds.pf.bmask = blue_max << blue_shift; > vs->clientds.pf.bits_per_pixel = bits_per_pixel; > @@ -2106,6 +2115,7 @@ static void vnc_connect(VncState *vs) > memset(vs->dirty_row, 0xFF, sizeof(vs->dirty_row)); > vs->has_resize = 0; > vs->has_hextile = 0; > + vs->has_WMVi = 0; > dcl->dpy_copy = NULL; > vnc_update_client(vs); > reset_keys(vs); > > > >