static int vnc_refresh_server_surface(VncDisplay *vd)

{

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

                    pixman_image_get_width(vd->server));

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

                     pixman_image_get_height(vd->server));

    int cmp_bytes, server_stride, min_stride, guest_stride, y = 0;

    uint8_t *guest_row0 = NULL, *server_row0;

    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.

     */

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

    server_stride = guest_stride = pixman_image_get_stride(vd->server);

    cmp_bytes = MIN(VNC_DIRTY_PIXELS_PER_BIT * VNC_SERVER_FB_BYTES,

                    server_stride);

    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);

    } else {

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

        guest_stride = pixman_image_get_stride(vd->guest.fb);

    }

    min_stride = MIN(server_stride, guest_stride);



    for (;;) {

        int x;

        uint8_t *guest_ptr, *server_ptr;

        unsigned long offset = find_next_bit((unsigned long *) &vd->guest.dirty,

                                             height * VNC_DIRTY_BPL(&vd->guest),

                                             y * VNC_DIRTY_BPL(&vd->guest));

        if (offset == height * VNC_DIRTY_BPL(&vd->guest)) {

            /* no more dirty bits */

            break;

        }

        y = offset / VNC_DIRTY_BPL(&vd->guest);

        x = offset % VNC_DIRTY_BPL(&vd->guest);



        server_ptr = server_row0 + y * server_stride + x * cmp_bytes;



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

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

            guest_ptr = (uint8_t *)pixman_image_get_data(tmpbuf);

        } else {

            guest_ptr = guest_row0 + y * guest_stride;

        }

        guest_ptr += x * cmp_bytes;



        for (; x < DIV_ROUND_UP(width, VNC_DIRTY_PIXELS_PER_BIT);

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

            int _cmp_bytes = cmp_bytes;

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

                continue;

            }

            if ((x + 1) * cmp_bytes > min_stride) {

                _cmp_bytes = min_stride - x * cmp_bytes;

            }

            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 * VNC_DIRTY_PIXELS_PER_BIT,

                                 y, &tv);

            }

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

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

            }

            has_dirty++;

        }



        y++;

    }

    qemu_pixman_image_unref(tmpbuf);

    return has_dirty;

}

static int vnc_refresh_server_surface(VncDisplay *vd)

{

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

                    pixman_image_get_width(vd->server));

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

                     pixman_image_get_height(vd->server));

    int cmp_bytes, server_stride, min_stride, guest_stride, y = 0;

    uint8_t *guest_row0 = NULL, *server_row0;

    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);

    }



    









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

    server_stride = guest_stride = pixman_image_get_stride(vd->server);

    cmp_bytes = MIN(VNC_DIRTY_PIXELS_PER_BIT * VNC_SERVER_FB_BYTES,

                    server_stride);

    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);

    } else {

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

        guest_stride = pixman_image_get_stride(vd->guest.fb);

    }

    min_stride = MIN(server_stride, guest_stride);



    for (;;) {

        int x;

        uint8_t *guest_ptr, *server_ptr;

        unsigned long offset = find_next_bit((unsigned long *) &vd->guest.dirty,

                                             height * VNC_DIRTY_BPL(&vd->guest),

                                             y * VNC_DIRTY_BPL(&vd->guest));

        if (offset == height * VNC_DIRTY_BPL(&vd->guest)) {

            

            break;

        }

        y = offset / VNC_DIRTY_BPL(&vd->guest);

        x = offset % VNC_DIRTY_BPL(&vd->guest);



        server_ptr = server_row0 + y * server_stride + x * cmp_bytes;



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

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

            guest_ptr = (uint8_t *)pixman_image_get_data(tmpbuf);

        } else {

            guest_ptr = guest_row0 + y * guest_stride;

        }

        guest_ptr += x * cmp_bytes;



        for (; x < DIV_ROUND_UP(width, VNC_DIRTY_PIXELS_PER_BIT);

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

            int _cmp_bytes = cmp_bytes;

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

                continue;

            }

            if ((x + 1) * cmp_bytes > min_stride) {

                _cmp_bytes = min_stride - x * cmp_bytes;

            }

            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 * VNC_DIRTY_PIXELS_PER_BIT,

                                 y, &tv);

            }

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

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

            }

            has_dirty++;

        }



        y++;

    }

    qemu_pixman_image_unref(tmpbuf);

    return has_dirty;

}

    int cmp_bytes, server_stride, min_stride, guest_stride, y = 0;     server_stride = guest_stride = pixman_image_get_stride(vd->server);     min_stride = MIN(server_stride, guest_stride);             if ((x + 1) * cmp_bytes > min_stride) {                 _cmp_bytes = min_stride - x * cmp_bytes;
static int FUNC_0(VncDisplay *VAR_0)

{

    int VAR_10 = MIN(pixman_image_get_width(VAR_0->guest.fb),

                    pixman_image_get_width(VAR_0->server));

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

                     pixman_image_get_height(VAR_0->server));

    int VAR_3, VAR_4, VAR_5, VAR_6, VAR_7 = 0;

    uint8_t *guest_row0 = NULL, *server_row0;

    VncState *vs;

    int VAR_8 = 0;

    pixman_image_t *tmpbuf = NULL;



    struct timeval VAR_9 = { 0, 0 };



    if (!VAR_0->non_adaptive) {

        gettimeofday(&VAR_9, NULL);

        VAR_8 = vnc_update_stats(VAR_0, &VAR_9);

    }



    









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

    VAR_4 = VAR_6 = pixman_image_get_stride(VAR_0->server);

    VAR_3 = MIN(VNC_DIRTY_PIXELS_PER_BIT * VNC_SERVER_FB_BYTES,

                    VAR_4);

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

        int VAR_10 = pixman_image_get_width(VAR_0->server);

        tmpbuf = qemu_pixman_linebuf_create(VNC_SERVER_FB_FORMAT, VAR_10);

    } else {

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

        VAR_6 = pixman_image_get_stride(VAR_0->guest.fb);

    }

    VAR_5 = MIN(VAR_4, VAR_6);



    for (;;) {

        int VAR_10;

        uint8_t *guest_ptr, *server_ptr;

        unsigned long VAR_11 = find_next_bit((unsigned long *) &VAR_0->guest.dirty,

                                             VAR_2 * VNC_DIRTY_BPL(&VAR_0->guest),

                                             VAR_7 * VNC_DIRTY_BPL(&VAR_0->guest));

        if (VAR_11 == VAR_2 * VNC_DIRTY_BPL(&VAR_0->guest)) {

            

            break;

        }

        VAR_7 = VAR_11 / VNC_DIRTY_BPL(&VAR_0->guest);

        VAR_10 = VAR_11 % VNC_DIRTY_BPL(&VAR_0->guest);



        server_ptr = server_row0 + VAR_7 * VAR_4 + VAR_10 * VAR_3;



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

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

            guest_ptr = (uint8_t *)pixman_image_get_data(tmpbuf);

        } else {

            guest_ptr = guest_row0 + VAR_7 * VAR_6;

        }

        guest_ptr += VAR_10 * VAR_3;



        for (; VAR_10 < DIV_ROUND_UP(VAR_10, VNC_DIRTY_PIXELS_PER_BIT);

             VAR_10++, guest_ptr += VAR_3, server_ptr += VAR_3) {

            int _cmp_bytes = VAR_3;

            if (!test_and_clear_bit(VAR_10, VAR_0->guest.dirty[VAR_7])) {

                continue;

            }

            if ((VAR_10 + 1) * VAR_3 > VAR_5) {

                _cmp_bytes = VAR_5 - VAR_10 * VAR_3;

            }

            if (memcmp(server_ptr, guest_ptr, _cmp_bytes) == 0) {

                continue;

            }

            memcpy(server_ptr, guest_ptr, _cmp_bytes);

            if (!VAR_0->non_adaptive) {

                vnc_rect_updated(VAR_0, VAR_10 * VNC_DIRTY_PIXELS_PER_BIT,

                                 VAR_7, &VAR_9);

            }

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

                set_bit(VAR_10, vs->dirty[VAR_7]);

            }

            VAR_8++;

        }



        VAR_7++;

    }

    qemu_pixman_image_unref(tmpbuf);

    return VAR_8;

}

static int FUNC_0(VncDisplay *VAR_0)
{ int VAR_10 = MIN(pixman_image_get_width(VAR_0->guest.fb),
pixman_image_get_width(VAR_0->server)); int VAR_2 = MIN(pixman_image_get_height(VAR_0->guest.fb),
pixman_image_get_height(VAR_0->server)); int VAR_3, VAR_4, VAR_5, VAR_6, VAR_7 = 0; uint8_t *guest_row0 = NULL, *server_row0; VncState *vs; int VAR_8 = 0; pixman_image_t *tmpbuf = NULL; struct timeval VAR_9 = { 0, 0 }; if (!VAR_0->non_adaptive) { gettimeofday(&VAR_9, NULL); VAR_8 = vnc_update_stats(VAR_0, &VAR_9); } server_row0 = (uint8_t *)pixman_image_get_data(VAR_0->server); VAR_4 = VAR_6 = pixman_image_get_stride(VAR_0->server); VAR_3 = MIN(VNC_DIRTY_PIXELS_PER_BIT * VNC_SERVER_FB_BYTES,
VAR_4); if (VAR_0->guest.format != VNC_SERVER_FB_FORMAT) { int VAR_10 = pixman_image_get_width(VAR_0->server); tmpbuf = qemu_pixman_linebuf_create(VNC_SERVER_FB_FORMAT, VAR_10); } else { guest_row0 = (uint8_t *)pixman_image_get_data(VAR_0->guest.fb); VAR_6 = pixman_image_get_stride(VAR_0->guest.fb); } VAR_5 = MIN(VAR_4, VAR_6); for (;;) { int VAR_10; uint8_t *guest_ptr, *server_ptr; unsigned long VAR_11 = find_next_bit((unsigned long *) &VAR_0->guest.dirty,
VAR_2 * VNC_DIRTY_BPL(&VAR_0->guest),
VAR_7 * VNC_DIRTY_BPL(&VAR_0->guest)); if (VAR_11 == VAR_2 * VNC_DIRTY_BPL(&VAR_0->guest)) { break; } VAR_7 = VAR_11 / VNC_DIRTY_BPL(&VAR_0->guest); VAR_10 = VAR_11 % VNC_DIRTY_BPL(&VAR_0->guest); server_ptr = server_row0 + VAR_7 * VAR_4 + VAR_10 * VAR_3; if (VAR_0->guest.format != VNC_SERVER_FB_FORMAT) { qemu_pixman_linebuf_fill(tmpbuf, VAR_0->guest.fb, VAR_10, 0, VAR_7); guest_ptr = (uint8_t *)pixman_image_get_data(tmpbuf); } else { guest_ptr = guest_row0 + VAR_7 * VAR_6; } guest_ptr += VAR_10 * VAR_3; for (; VAR_10 < DIV_ROUND_UP(VAR_10, VNC_DIRTY_PIXELS_PER_BIT); VAR_10++, guest_ptr += VAR_3, server_ptr += VAR_3) { int _cmp_bytes = VAR_3; if (!test_and_clear_bit(VAR_10, VAR_0->guest.dirty[VAR_7])) { continue; } if ((VAR_10 + 1) * VAR_3 > VAR_5) { _cmp_bytes = VAR_5 - VAR_10 * VAR_3; } if (memcmp(server_ptr, guest_ptr, _cmp_bytes) == 0) { continue; } memcpy(server_ptr, guest_ptr, _cmp_bytes); if (!VAR_0->non_adaptive) { vnc_rect_updated(VAR_0, VAR_10 * VNC_DIRTY_PIXELS_PER_BIT,
VAR_7, &VAR_9); } QTAILQ_FOREACH(vs, &VAR_0->clients, next) { set_bit(VAR_10, vs->dirty[VAR_7]); } VAR_8++; } VAR_7++; } qemu_pixman_image_unref(tmpbuf); return VAR_8; }