static void vnc_refresh(void *opaque)

{

    VncDisplay *vd = opaque;

    VncState *vs, *vn;

    int has_dirty, rects = 0;



    vga_hw_update();



    if (vnc_trylock_display(vd)) {

        vd->timer_interval = VNC_REFRESH_INTERVAL_BASE;

        qemu_mod_timer(vd->timer, qemu_get_clock(rt_clock) +

                       vd->timer_interval);

        return;

    }



    has_dirty = vnc_refresh_server_surface(vd);

    vnc_unlock_display(vd);



    QTAILQ_FOREACH_SAFE(vs, &vd->clients, next, vn) {

        rects += vnc_update_client(vs, has_dirty);

        /* vs might be free()ed here */

    }



    /* vd->timer could be NULL now if the last client disconnected,

     * in this case don't update the timer */

    if (vd->timer == NULL)

        return;



    if (has_dirty && rects) {

        vd->timer_interval /= 2;

        if (vd->timer_interval < VNC_REFRESH_INTERVAL_BASE)

            vd->timer_interval = VNC_REFRESH_INTERVAL_BASE;

    } else {

        vd->timer_interval += VNC_REFRESH_INTERVAL_INC;

        if (vd->timer_interval > VNC_REFRESH_INTERVAL_MAX)

            vd->timer_interval = VNC_REFRESH_INTERVAL_MAX;

    }

    qemu_mod_timer(vd->timer, qemu_get_clock(rt_clock) + vd->timer_interval);

}

static void vnc_refresh(void *opaque)

{

    VncDisplay *vd = opaque;

    VncState *vs, *vn;

    int has_dirty, rects = 0;



    vga_hw_update();



    if (vnc_trylock_display(vd)) {

        vd->timer_interval = VNC_REFRESH_INTERVAL_BASE;

        qemu_mod_timer(vd->timer, qemu_get_clock(rt_clock) +

                       vd->timer_interval);

        return;

    }



    has_dirty = vnc_refresh_server_surface(vd);

    vnc_unlock_display(vd);



    QTAILQ_FOREACH_SAFE(vs, &vd->clients, next, vn) {

        rects += vnc_update_client(vs, has_dirty);

        

    }



    



    if (vd->timer == NULL)

        return;



    if (has_dirty && rects) {

        vd->timer_interval /= 2;

        if (vd->timer_interval < VNC_REFRESH_INTERVAL_BASE)

            vd->timer_interval = VNC_REFRESH_INTERVAL_BASE;

    } else {

        vd->timer_interval += VNC_REFRESH_INTERVAL_INC;

        if (vd->timer_interval > VNC_REFRESH_INTERVAL_MAX)

            vd->timer_interval = VNC_REFRESH_INTERVAL_MAX;

    }

    qemu_mod_timer(vd->timer, qemu_get_clock(rt_clock) + vd->timer_interval);

}

static void FUNC_0(void *VAR_0)

{

    VncDisplay *vd = VAR_0;

    VncState *vs, *vn;

    int VAR_1, VAR_2 = 0;



    vga_hw_update();



    if (vnc_trylock_display(vd)) {

        vd->timer_interval = VNC_REFRESH_INTERVAL_BASE;

        qemu_mod_timer(vd->timer, qemu_get_clock(rt_clock) +

                       vd->timer_interval);

        return;

    }



    VAR_1 = vnc_refresh_server_surface(vd);

    vnc_unlock_display(vd);



    QTAILQ_FOREACH_SAFE(vs, &vd->clients, next, vn) {

        VAR_2 += vnc_update_client(vs, VAR_1);

        

    }



    



    if (vd->timer == NULL)

        return;



    if (VAR_1 && VAR_2) {

        vd->timer_interval /= 2;

        if (vd->timer_interval < VNC_REFRESH_INTERVAL_BASE)

            vd->timer_interval = VNC_REFRESH_INTERVAL_BASE;

    } else {

        vd->timer_interval += VNC_REFRESH_INTERVAL_INC;

        if (vd->timer_interval > VNC_REFRESH_INTERVAL_MAX)

            vd->timer_interval = VNC_REFRESH_INTERVAL_MAX;

    }

    qemu_mod_timer(vd->timer, qemu_get_clock(rt_clock) + vd->timer_interval);

}

static void FUNC_0(void *VAR_0)
{ VncDisplay *vd = VAR_0; VncState *vs, *vn; int VAR_1, VAR_2 = 0; vga_hw_update(); if (vnc_trylock_display(vd)) { vd->timer_interval = VNC_REFRESH_INTERVAL_BASE; qemu_mod_timer(vd->timer, qemu_get_clock(rt_clock) +
vd->timer_interval); return; } VAR_1 = vnc_refresh_server_surface(vd); vnc_unlock_display(vd); QTAILQ_FOREACH_SAFE(vs, &vd->clients, next, vn) { VAR_2 += vnc_update_client(vs, VAR_1); } if (vd->timer == NULL)
return; if (VAR_1 && VAR_2) { vd->timer_interval /= 2; if (vd->timer_interval < VNC_REFRESH_INTERVAL_BASE)
vd->timer_interval = VNC_REFRESH_INTERVAL_BASE; } else { vd->timer_interval += VNC_REFRESH_INTERVAL_INC; if (vd->timer_interval > VNC_REFRESH_INTERVAL_MAX)
vd->timer_interval = VNC_REFRESH_INTERVAL_MAX; } qemu_mod_timer(vd->timer, qemu_get_clock(rt_clock) + vd->timer_interval); }