From patchwork Wed Aug 11 05:49:42 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Chary X-Patchwork-Id: 61450 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6C3A4B6F14 for ; Wed, 11 Aug 2010 16:15:36 +1000 (EST) Received: from localhost ([127.0.0.1]:36220 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Oj4ar-0000kH-IG for incoming@patchwork.ozlabs.org; Wed, 11 Aug 2010 02:15:17 -0400 Received: from [140.186.70.92] (port=37997 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Oj4DJ-000658-Ut for qemu-devel@nongnu.org; Wed, 11 Aug 2010 01:50:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Oj4DI-0007Ve-CE for qemu-devel@nongnu.org; Wed, 11 Aug 2010 01:50:57 -0400 Received: from relay1-v.mail.gandi.net ([217.70.178.75]:53581 helo=mrelay1-v.mgt.gandi.net) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Oj4DI-0007VT-0G for qemu-devel@nongnu.org; Wed, 11 Aug 2010 01:50:56 -0400 X-Originating-IP: 217.70.178.36 Received: from mfilter2-v.gandi.net (mfilter2-v.gandi.net [217.70.178.36]) by mrelay1-v.mgt.gandi.net (Postfix) with ESMTP id 7CEEE362B8; Wed, 11 Aug 2010 07:50:55 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter2-v.gandi.net Received: from mrelay1-v.mgt.gandi.net ([217.70.178.75]) by mfilter2-v.gandi.net (mfilter2-v.gandi.net [217.70.178.36]) (amavisd-new, port 10024) with ESMTP id K9V1VcA61pRj; Wed, 11 Aug 2010 07:50:54 +0200 (CEST) X-Originating-IP: 82.241.209.44 Received: from tartiflon (falgoret.iksaif.net [82.241.209.44]) (Authenticated sender: fake@iksaif.net) by mrelay1-v.mgt.gandi.net (Postfix) with ESMTPSA id 3719A362AA; Wed, 11 Aug 2010 07:50:48 +0200 (CEST) From: Corentin Chary To: Qemu-development List Date: Wed, 11 Aug 2010 07:49:42 +0200 Message-Id: <1281505785-22523-13-git-send-email-corentincj@iksaif.net> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1281505785-22523-1-git-send-email-corentincj@iksaif.net> References: <1281505785-22523-1-git-send-email-corentincj@iksaif.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: Corentin Chary , Anthony Liguori , Alexander Graf , Andre Przywara Subject: [Qemu-devel] [PATCH 12/15] vnc: use the new generic bitmap functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Switch to bitmap.h and bitops.h instead of redefining our own bitmap helpers. Signed-off-by: Corentin Chary --- ui/vnc.c | 91 ++++++++++++++----------------------------------------------- ui/vnc.h | 7 +++-- 2 files changed, 25 insertions(+), 73 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index 5038863..0adab4a 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -41,13 +41,6 @@ static const struct timeval VNC_REFRESH_LOSSY = { 2, 0 }; #include "vnc_keysym.h" #include "d3des.h" -#define count_bits(c, v) { \ - for (c = 0; v; v >>= 1) \ - { \ - c += v & 1; \ - } \ -} - static VncDisplay *vnc_display; /* needed for info vnc */ static DisplayChangeListener *dcl; @@ -374,47 +367,6 @@ static void framebuffer_update_request(VncState *vs, int incremental, static void vnc_refresh(void *opaque); static int vnc_refresh_server_surface(VncDisplay *vd); -static inline void vnc_set_bit(uint32_t *d, int k) -{ - d[k >> 5] |= 1 << (k & 0x1f); -} - -static inline void vnc_clear_bit(uint32_t *d, int k) -{ - d[k >> 5] &= ~(1 << (k & 0x1f)); -} - -static inline void vnc_set_bits(uint32_t *d, int n, int nb_words) -{ - int j; - - j = 0; - while (n >= 32) { - d[j++] = -1; - n -= 32; - } - if (n > 0) - d[j++] = (1 << n) - 1; - while (j < nb_words) - d[j++] = 0; -} - -static inline int vnc_get_bit(const uint32_t *d, int k) -{ - return (d[k >> 5] >> (k & 0x1f)) & 1; -} - -static inline int vnc_and_bits(const uint32_t *d1, const uint32_t *d2, - int nb_words) -{ - int i; - for(i = 0; i < nb_words; i++) { - if ((d1[i] & d2[i]) != 0) - return 1; - } - return 0; -} - static void vnc_dpy_update(DisplayState *ds, int x, int y, int w, int h) { int i; @@ -437,7 +389,7 @@ static void vnc_dpy_update(DisplayState *ds, int x, int y, int w, int h) for (; y < h; y++) for (i = 0; i < w; i += 16) - vnc_set_bit(s->dirty[y], (x + i) / 16); + set_bit((x + i) / 16, s->dirty[y]); } void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h, @@ -776,7 +728,7 @@ static void vnc_dpy_copy(DisplayState *ds, int src_x, int src_y, int dst_x, int memmove(dst_row, src_row, cmp_bytes); QTAILQ_FOREACH(vs, &vd->clients, next) { if (!vnc_has_feature(vs, VNC_FEATURE_COPYRECT)) { - vnc_set_bit(vs->dirty[y], ((x + dst_x) / 16)); + set_bit(((x + dst_x) / 16), vs->dirty[y]); } } } @@ -846,10 +798,12 @@ static int find_and_clear_dirty_height(struct VncState *vs, for (h = 1; h < (vd->server->height - y); h++) { int tmp_x; - if (!vnc_get_bit(vs->dirty[y + h], last_x)) + if (!test_bit(last_x, vs->dirty[y + h])) { break; - for (tmp_x = last_x; tmp_x < x; tmp_x++) - vnc_clear_bit(vs->dirty[y + h], tmp_x); + } + for (tmp_x = last_x; tmp_x < x; tmp_x++) { + clear_bit(tmp_x, vs->dirty[y + h]); + } } return h; @@ -901,11 +855,10 @@ static int vnc_update_client(VncState *vs, int has_dirty) int x; int last_x = -1; for (x = 0; x < width / 16; x++) { - if (vnc_get_bit(vs->dirty[y], x)) { + if (test_and_clear_bit(x, vs->dirty[y])) { if (last_x == -1) { last_x = x; } - vnc_clear_bit(vs->dirty[y], x); } else { if (last_x != -1) { int h = find_and_clear_dirty_height(vs, y, last_x, x); @@ -1698,8 +1651,7 @@ static void framebuffer_update_request(VncState *vs, int incremental, if (!incremental) { vs->force_update = 1; for (i = 0; i < h; i++) { - vnc_set_bits(vs->dirty[y_position + i], - (ds_get_width(vs->ds) / 16), VNC_DIRTY_WORDS); + bitmap_set(vs->dirty[y_position + i], x_position / 16, w / 16); } } } @@ -1838,15 +1790,15 @@ static void set_pixel_format(VncState *vs, vs->clientds = *(vs->vd->guest.ds); vs->clientds.pf.rmax = red_max; - count_bits(vs->clientds.pf.rbits, red_max); + vs->clientds.pf.rbits = hweight_long(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.gbits = hweight_long(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.bbits = hweight_long(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; @@ -2310,7 +2262,7 @@ static int vnc_refresh_lossy_rect(VncDisplay *vd, int x, int y) x = x / VNC_STAT_RECT * VNC_STAT_RECT; QTAILQ_FOREACH(vs, &vd->clients, next) { - int j, i; + int j; /* kernel send buffers are full -> refresh later */ if (vs->output.offset) @@ -2321,9 +2273,7 @@ static int vnc_refresh_lossy_rect(VncDisplay *vd, int x, int y) vs->lossy_rect[sty][stx] = 0; for (j = 0; j < VNC_STAT_RECT; ++j) { - for (i = x / 16; i < VNC_STAT_RECT / 16 + x / 16; ++i) { - vnc_set_bit(vs->dirty[y + j], i); - } + bitmap_set(vs->dirty[y + j], x / 16, VNC_STAT_RECT / 16); } has_dirty++; } @@ -2426,7 +2376,7 @@ static int vnc_refresh_server_surface(VncDisplay *vd) uint8_t *guest_row; uint8_t *server_row; int cmp_bytes; - uint32_t width_mask[VNC_DIRTY_WORDS]; + unsigned long width_mask[VNC_DIRTY_WORDS]; VncState *vs; int has_dirty = 0; @@ -2440,12 +2390,14 @@ static int vnc_refresh_server_surface(VncDisplay *vd) * Check and copy modified bits from guest to server surface. * Update server dirty map. */ - vnc_set_bits(width_mask, (ds_get_width(vd->ds) / 16), VNC_DIRTY_WORDS); + bitmap_set(width_mask, 0, (ds_get_width(vd->ds) / 16)); + bitmap_clear(width_mask, (ds_get_width(vd->ds) / 16), + VNC_DIRTY_WORDS * BITS_PER_LONG); cmp_bytes = 16 * ds_get_bytes_per_pixel(vd->ds); guest_row = vd->guest.ds->data; server_row = vd->server->data; for (y = 0; y < vd->guest.ds->height; y++) { - if (vnc_and_bits(vd->guest.dirty[y], width_mask, VNC_DIRTY_WORDS)) { + if (bitmap_intersects(vd->guest.dirty[y], width_mask, VNC_DIRTY_WORDS)) { int x; uint8_t *guest_ptr; uint8_t *server_ptr; @@ -2455,15 +2407,14 @@ static int vnc_refresh_server_surface(VncDisplay *vd) for (x = 0; x < vd->guest.ds->width; x += 16, guest_ptr += cmp_bytes, server_ptr += cmp_bytes) { - if (!vnc_get_bit(vd->guest.dirty[y], (x / 16))) + if (!test_and_clear_bit((x / 16), vd->guest.dirty[y])) continue; - vnc_clear_bit(vd->guest.dirty[y], (x / 16)); if (memcmp(server_ptr, guest_ptr, cmp_bytes) == 0) continue; memcpy(server_ptr, guest_ptr, cmp_bytes); vnc_rect_updated(vd, x, y, &tv); QTAILQ_FOREACH(vs, &vd->clients, next) { - vnc_set_bit(vs->dirty[y], (x / 16)); + set_bit((x / 16), vs->dirty[y]); } has_dirty++; } diff --git a/ui/vnc.h b/ui/vnc.h index 5cfa247..979467b 100644 --- a/ui/vnc.h +++ b/ui/vnc.h @@ -35,6 +35,7 @@ #include "console.h" #include "monitor.h" #include "audio/audio.h" +#include "bitmap.h" #include #include @@ -80,7 +81,7 @@ typedef void VncSendHextileTile(VncState *vs, #define VNC_MAX_WIDTH 2560 #define VNC_MAX_HEIGHT 2048 -#define VNC_DIRTY_WORDS (VNC_MAX_WIDTH / (16 * 32)) +#define VNC_DIRTY_WORDS (VNC_MAX_WIDTH / (16 * BITS_PER_LONG)) #define VNC_STAT_RECT 64 #define VNC_STAT_COLS (VNC_MAX_WIDTH / VNC_STAT_RECT) @@ -113,7 +114,7 @@ typedef struct VncRectStat VncRectStat; struct VncSurface { struct timeval last_freq_check; - uint32_t dirty[VNC_MAX_HEIGHT][VNC_DIRTY_WORDS]; + unsigned long dirty[VNC_MAX_HEIGHT][VNC_DIRTY_WORDS]; VncRectStat stats[VNC_STAT_ROWS][VNC_STAT_COLS]; DisplaySurface *ds; }; @@ -231,7 +232,7 @@ struct VncState int csock; DisplayState *ds; - uint32_t dirty[VNC_MAX_HEIGHT][VNC_DIRTY_WORDS]; + unsigned long dirty[VNC_MAX_HEIGHT][VNC_DIRTY_WORDS]; uint8_t **lossy_rect; /* Not an Array to avoid costly memcpy in * vnc-jobs-async.c */