static int vnc_refresh_server_surface(VncDisplay *vd)

{

    int width = pixman_image_get_width(vd->guest.fb);

    int height = pixman_image_get_height(vd->guest.fb);

    int y;

    uint8_t *guest_row;

    uint8_t *server_row;

    int cmp_bytes;

    VncState *vs;

    int has_dirty = 0;

    pixman_image_t *tmpbuf = NULL;



    struct timeval tv = { 0, 0 };



    if (!vd->non_adaptive) {

        gettimeofday(&tv, NULL);

        has_dirty = vnc_update_stats(vd, &tv);

    }



    /*

     * Walk through the guest dirty map.

     * Check and copy modified bits from guest to server surface.

     * Update server dirty map.

     */

    cmp_bytes = 64;

    if (cmp_bytes > vnc_server_fb_stride(vd)) {

        cmp_bytes = vnc_server_fb_stride(vd);

    }

    if (vd->guest.format != VNC_SERVER_FB_FORMAT) {

        int width = pixman_image_get_width(vd->server);

        tmpbuf = qemu_pixman_linebuf_create(VNC_SERVER_FB_FORMAT, width);

    }

    guest_row = (uint8_t *)pixman_image_get_data(vd->guest.fb);

    server_row = (uint8_t *)pixman_image_get_data(vd->server);

    for (y = 0; y < height; y++) {

        if (!bitmap_empty(vd->guest.dirty[y], VNC_DIRTY_BITS)) {

            int x;

            uint8_t *guest_ptr;

            uint8_t *server_ptr;



            if (vd->guest.format != VNC_SERVER_FB_FORMAT) {

                qemu_pixman_linebuf_fill(tmpbuf, vd->guest.fb, width, y);

                guest_ptr = (uint8_t *)pixman_image_get_data(tmpbuf);

            } else {

                guest_ptr = guest_row;

            }

            server_ptr = server_row;



            for (x = 0; x + 15 < width;

                    x += 16, guest_ptr += cmp_bytes, server_ptr += cmp_bytes) {

                if (!test_and_clear_bit((x / 16), vd->guest.dirty[y]))

                    continue;

                if (memcmp(server_ptr, guest_ptr, cmp_bytes) == 0)

                    continue;

                memcpy(server_ptr, guest_ptr, cmp_bytes);

                if (!vd->non_adaptive)

                    vnc_rect_updated(vd, x, y, &tv);

                QTAILQ_FOREACH(vs, &vd->clients, next) {

                    set_bit((x / 16), vs->dirty[y]);

                }

                has_dirty++;

            }

        }

        guest_row  += pixman_image_get_stride(vd->guest.fb);

        server_row += pixman_image_get_stride(vd->server);

    }

    qemu_pixman_image_unref(tmpbuf);

    return has_dirty;

}

static int vnc_refresh_server_surface(VncDisplay *vd)

{

    int width = pixman_image_get_width(vd->guest.fb);

    int height = pixman_image_get_height(vd->guest.fb);

    int y;

    uint8_t *guest_row;

    uint8_t *server_row;

    int cmp_bytes;

    VncState *vs;

    int has_dirty = 0;

    pixman_image_t *tmpbuf = NULL;



    struct timeval tv = { 0, 0 };



    if (!vd->non_adaptive) {

        gettimeofday(&tv, NULL);

        has_dirty = vnc_update_stats(vd, &tv);

    }



    









    cmp_bytes = 64;

    if (cmp_bytes > vnc_server_fb_stride(vd)) {

        cmp_bytes = vnc_server_fb_stride(vd);

    }

    if (vd->guest.format != VNC_SERVER_FB_FORMAT) {

        int width = pixman_image_get_width(vd->server);

        tmpbuf = qemu_pixman_linebuf_create(VNC_SERVER_FB_FORMAT, width);

    }

    guest_row = (uint8_t *)pixman_image_get_data(vd->guest.fb);

    server_row = (uint8_t *)pixman_image_get_data(vd->server);

    for (y = 0; y < height; y++) {

        if (!bitmap_empty(vd->guest.dirty[y], VNC_DIRTY_BITS)) {

            int x;

            uint8_t *guest_ptr;

            uint8_t *server_ptr;



            if (vd->guest.format != VNC_SERVER_FB_FORMAT) {

                qemu_pixman_linebuf_fill(tmpbuf, vd->guest.fb, width, y);

                guest_ptr = (uint8_t *)pixman_image_get_data(tmpbuf);

            } else {

                guest_ptr = guest_row;

            }

            server_ptr = server_row;



            for (x = 0; x + 15 < width;

                    x += 16, guest_ptr += cmp_bytes, server_ptr += cmp_bytes) {

                if (!test_and_clear_bit((x / 16), vd->guest.dirty[y]))

                    continue;

                if (memcmp(server_ptr, guest_ptr, cmp_bytes) == 0)

                    continue;

                memcpy(server_ptr, guest_ptr, cmp_bytes);

                if (!vd->non_adaptive)

                    vnc_rect_updated(vd, x, y, &tv);

                QTAILQ_FOREACH(vs, &vd->clients, next) {

                    set_bit((x / 16), vs->dirty[y]);

                }

                has_dirty++;

            }

        }

        guest_row  += pixman_image_get_stride(vd->guest.fb);

        server_row += pixman_image_get_stride(vd->server);

    }

    qemu_pixman_image_unref(tmpbuf);

    return has_dirty;

}

static int FUNC_0(VncDisplay *VAR_0)

{

    int VAR_7 = pixman_image_get_width(VAR_0->guest.fb);

    int VAR_2 = pixman_image_get_height(VAR_0->guest.fb);

    int VAR_3;

    uint8_t *guest_row;

    uint8_t *server_row;

    int VAR_4;

    VncState *vs;

    int VAR_5 = 0;

    pixman_image_t *tmpbuf = NULL;



    struct timeval VAR_6 = { 0, 0 };



    if (!VAR_0->non_adaptive) {

        gettimeofday(&VAR_6, NULL);

        VAR_5 = vnc_update_stats(VAR_0, &VAR_6);

    }



    









    VAR_4 = 64;

    if (VAR_4 > vnc_server_fb_stride(VAR_0)) {

        VAR_4 = vnc_server_fb_stride(VAR_0);

    }

    if (VAR_0->guest.format != VNC_SERVER_FB_FORMAT) {

        int VAR_7 = pixman_image_get_width(VAR_0->server);

        tmpbuf = qemu_pixman_linebuf_create(VNC_SERVER_FB_FORMAT, VAR_7);

    }

    guest_row = (uint8_t *)pixman_image_get_data(VAR_0->guest.fb);

    server_row = (uint8_t *)pixman_image_get_data(VAR_0->server);

    for (VAR_3 = 0; VAR_3 < VAR_2; VAR_3++) {

        if (!bitmap_empty(VAR_0->guest.dirty[VAR_3], VNC_DIRTY_BITS)) {

            int VAR_7;

            uint8_t *guest_ptr;

            uint8_t *server_ptr;



            if (VAR_0->guest.format != VNC_SERVER_FB_FORMAT) {

                qemu_pixman_linebuf_fill(tmpbuf, VAR_0->guest.fb, VAR_7, VAR_3);

                guest_ptr = (uint8_t *)pixman_image_get_data(tmpbuf);

            } else {

                guest_ptr = guest_row;

            }

            server_ptr = server_row;



            for (VAR_7 = 0; VAR_7 + 15 < VAR_7;

                    VAR_7 += 16, guest_ptr += VAR_4, server_ptr += VAR_4) {

                if (!test_and_clear_bit((VAR_7 / 16), VAR_0->guest.dirty[VAR_3]))

                    continue;

                if (memcmp(server_ptr, guest_ptr, VAR_4) == 0)

                    continue;

                memcpy(server_ptr, guest_ptr, VAR_4);

                if (!VAR_0->non_adaptive)

                    vnc_rect_updated(VAR_0, VAR_7, VAR_3, &VAR_6);

                QTAILQ_FOREACH(vs, &VAR_0->clients, next) {

                    set_bit((VAR_7 / 16), vs->dirty[VAR_3]);

                }

                VAR_5++;

            }

        }

        guest_row  += pixman_image_get_stride(VAR_0->guest.fb);

        server_row += pixman_image_get_stride(VAR_0->server);

    }

    qemu_pixman_image_unref(tmpbuf);

    return VAR_5;

}

static int FUNC_0(VncDisplay *VAR_0)
{ int VAR_7 = pixman_image_get_width(VAR_0->guest.fb); int VAR_2 = pixman_image_get_height(VAR_0->guest.fb); int VAR_3; uint8_t *guest_row; uint8_t *server_row; int VAR_4; VncState *vs; int VAR_5 = 0; pixman_image_t *tmpbuf = NULL; struct timeval VAR_6 = { 0, 0 }; if (!VAR_0->non_adaptive) { gettimeofday(&VAR_6, NULL); VAR_5 = vnc_update_stats(VAR_0, &VAR_6); } VAR_4 = 64; if (VAR_4 > vnc_server_fb_stride(VAR_0)) { VAR_4 = vnc_server_fb_stride(VAR_0); } if (VAR_0->guest.format != VNC_SERVER_FB_FORMAT) { int VAR_7 = pixman_image_get_width(VAR_0->server); tmpbuf = qemu_pixman_linebuf_create(VNC_SERVER_FB_FORMAT, VAR_7); } guest_row = (uint8_t *)pixman_image_get_data(VAR_0->guest.fb); server_row = (uint8_t *)pixman_image_get_data(VAR_0->server); for (VAR_3 = 0; VAR_3 < VAR_2; VAR_3++) { if (!bitmap_empty(VAR_0->guest.dirty[VAR_3], VNC_DIRTY_BITS)) { int VAR_7; uint8_t *guest_ptr; uint8_t *server_ptr; if (VAR_0->guest.format != VNC_SERVER_FB_FORMAT) { qemu_pixman_linebuf_fill(tmpbuf, VAR_0->guest.fb, VAR_7, VAR_3); guest_ptr = (uint8_t *)pixman_image_get_data(tmpbuf); } else { guest_ptr = guest_row; } server_ptr = server_row; for (VAR_7 = 0; VAR_7 + 15 < VAR_7; VAR_7 += 16, guest_ptr += VAR_4, server_ptr += VAR_4) { if (!test_and_clear_bit((VAR_7 / 16), VAR_0->guest.dirty[VAR_3]))
continue; if (memcmp(server_ptr, guest_ptr, VAR_4) == 0)
continue; memcpy(server_ptr, guest_ptr, VAR_4); if (!VAR_0->non_adaptive)
vnc_rect_updated(VAR_0, VAR_7, VAR_3, &VAR_6); QTAILQ_FOREACH(vs, &VAR_0->clients, next) { set_bit((VAR_7 / 16), vs->dirty[VAR_3]); } VAR_5++; } } guest_row  += pixman_image_get_stride(VAR_0->guest.fb); server_row += pixman_image_get_stride(VAR_0->server); } qemu_pixman_image_unref(tmpbuf); return VAR_5; }