void qemu_spice_display_switch(SimpleSpiceDisplay *ssd,

                               DisplaySurface *surface)

{

    SimpleSpiceUpdate *update;

    bool need_destroy;



    if (surface && ssd->surface &&

        surface_width(surface) == pixman_image_get_width(ssd->surface) &&

        surface_height(surface) == pixman_image_get_height(ssd->surface)) {

        /* no-resize fast path: just swap backing store */

        dprint(1, "%s/%d: fast (%dx%d)\n", __func__, ssd->qxl.id,

               surface_width(surface), surface_height(surface));

        qemu_mutex_lock(&ssd->lock);

        ssd->ds = surface;

        pixman_image_unref(ssd->surface);

        ssd->surface = pixman_image_ref(ssd->ds->image);

        qemu_mutex_unlock(&ssd->lock);

        qemu_spice_display_update(ssd, 0, 0,

                                  surface_width(surface),

                                  surface_height(surface));

        return;

    }



    /* full mode switch */

    dprint(1, "%s/%d: full (%dx%d -> %dx%d)\n", __func__, ssd->qxl.id,

           ssd->surface ? pixman_image_get_width(ssd->surface)  : 0,

           ssd->surface ? pixman_image_get_height(ssd->surface) : 0,

           surface ? surface_width(surface)  : 0,

           surface ? surface_height(surface) : 0);



    memset(&ssd->dirty, 0, sizeof(ssd->dirty));

    if (ssd->surface) {

        pixman_image_unref(ssd->surface);

        ssd->surface = NULL;

        pixman_image_unref(ssd->mirror);

        ssd->mirror = NULL;

    }



    qemu_mutex_lock(&ssd->lock);

    need_destroy = (ssd->ds != NULL);

    ssd->ds = surface;

    while ((update = QTAILQ_FIRST(&ssd->updates)) != NULL) {

        QTAILQ_REMOVE(&ssd->updates, update, next);

        qemu_spice_destroy_update(ssd, update);

    }

    qemu_mutex_unlock(&ssd->lock);

    if (need_destroy) {

        qemu_spice_destroy_host_primary(ssd);

    }

    if (ssd->ds) {

        ssd->surface = pixman_image_ref(ssd->ds->image);

        ssd->mirror  = qemu_pixman_mirror_create(ssd->ds->format,

                                                 ssd->ds->image);

        qemu_spice_create_host_primary(ssd);

    }



    memset(&ssd->dirty, 0, sizeof(ssd->dirty));

    ssd->notify++;

}

void qemu_spice_display_switch(SimpleSpiceDisplay *ssd,

                               DisplaySurface *surface)

{

    SimpleSpiceUpdate *update;

    bool need_destroy;



    if (surface && ssd->surface &&

        surface_width(surface) == pixman_image_get_width(ssd->surface) &&

        surface_height(surface) == pixman_image_get_height(ssd->surface)) {

        

        dprint(1, "%s/%d: fast (%dx%d)\n", __func__, ssd->qxl.id,

               surface_width(surface), surface_height(surface));

        qemu_mutex_lock(&ssd->lock);

        ssd->ds = surface;

        pixman_image_unref(ssd->surface);

        ssd->surface = pixman_image_ref(ssd->ds->image);

        qemu_mutex_unlock(&ssd->lock);

        qemu_spice_display_update(ssd, 0, 0,

                                  surface_width(surface),

                                  surface_height(surface));

        return;

    }



    

    dprint(1, "%s/%d: full (%dx%d -> %dx%d)\n", __func__, ssd->qxl.id,

           ssd->surface ? pixman_image_get_width(ssd->surface)  : 0,

           ssd->surface ? pixman_image_get_height(ssd->surface) : 0,

           surface ? surface_width(surface)  : 0,

           surface ? surface_height(surface) : 0);



    memset(&ssd->dirty, 0, sizeof(ssd->dirty));

    if (ssd->surface) {

        pixman_image_unref(ssd->surface);

        ssd->surface = NULL;

        pixman_image_unref(ssd->mirror);

        ssd->mirror = NULL;

    }



    qemu_mutex_lock(&ssd->lock);

    need_destroy = (ssd->ds != NULL);

    ssd->ds = surface;

    while ((update = QTAILQ_FIRST(&ssd->updates)) != NULL) {

        QTAILQ_REMOVE(&ssd->updates, update, next);

        qemu_spice_destroy_update(ssd, update);

    }

    qemu_mutex_unlock(&ssd->lock);

    if (need_destroy) {

        qemu_spice_destroy_host_primary(ssd);

    }

    if (ssd->ds) {

        ssd->surface = pixman_image_ref(ssd->ds->image);

        ssd->mirror  = qemu_pixman_mirror_create(ssd->ds->format,

                                                 ssd->ds->image);

        qemu_spice_create_host_primary(ssd);

    }



    memset(&ssd->dirty, 0, sizeof(ssd->dirty));

    ssd->notify++;

}

void FUNC_0(SimpleSpiceDisplay *VAR_0,

                               DisplaySurface *VAR_1)

{

    SimpleSpiceUpdate *update;

    bool need_destroy;



    if (VAR_1 && VAR_0->VAR_1 &&

        surface_width(VAR_1) == pixman_image_get_width(VAR_0->VAR_1) &&

        surface_height(VAR_1) == pixman_image_get_height(VAR_0->VAR_1)) {

        

        dprint(1, "%s/%d: fast (%dx%d)\n", __func__, VAR_0->qxl.id,

               surface_width(VAR_1), surface_height(VAR_1));

        qemu_mutex_lock(&VAR_0->lock);

        VAR_0->ds = VAR_1;

        pixman_image_unref(VAR_0->VAR_1);

        VAR_0->VAR_1 = pixman_image_ref(VAR_0->ds->image);

        qemu_mutex_unlock(&VAR_0->lock);

        qemu_spice_display_update(VAR_0, 0, 0,

                                  surface_width(VAR_1),

                                  surface_height(VAR_1));

        return;

    }



    

    dprint(1, "%s/%d: full (%dx%d -> %dx%d)\n", __func__, VAR_0->qxl.id,

           VAR_0->VAR_1 ? pixman_image_get_width(VAR_0->VAR_1)  : 0,

           VAR_0->VAR_1 ? pixman_image_get_height(VAR_0->VAR_1) : 0,

           VAR_1 ? surface_width(VAR_1)  : 0,

           VAR_1 ? surface_height(VAR_1) : 0);



    memset(&VAR_0->dirty, 0, sizeof(VAR_0->dirty));

    if (VAR_0->VAR_1) {

        pixman_image_unref(VAR_0->VAR_1);

        VAR_0->VAR_1 = NULL;

        pixman_image_unref(VAR_0->mirror);

        VAR_0->mirror = NULL;

    }



    qemu_mutex_lock(&VAR_0->lock);

    need_destroy = (VAR_0->ds != NULL);

    VAR_0->ds = VAR_1;

    while ((update = QTAILQ_FIRST(&VAR_0->updates)) != NULL) {

        QTAILQ_REMOVE(&VAR_0->updates, update, next);

        qemu_spice_destroy_update(VAR_0, update);

    }

    qemu_mutex_unlock(&VAR_0->lock);

    if (need_destroy) {

        qemu_spice_destroy_host_primary(VAR_0);

    }

    if (VAR_0->ds) {

        VAR_0->VAR_1 = pixman_image_ref(VAR_0->ds->image);

        VAR_0->mirror  = qemu_pixman_mirror_create(VAR_0->ds->format,

                                                 VAR_0->ds->image);

        qemu_spice_create_host_primary(VAR_0);

    }



    memset(&VAR_0->dirty, 0, sizeof(VAR_0->dirty));

    VAR_0->notify++;

}

void FUNC_0(SimpleSpiceDisplay *VAR_0,
DisplaySurface *VAR_1)
{ SimpleSpiceUpdate *update; bool need_destroy; if (VAR_1 && VAR_0->VAR_1 &&
surface_width(VAR_1) == pixman_image_get_width(VAR_0->VAR_1) &&
surface_height(VAR_1) == pixman_image_get_height(VAR_0->VAR_1)) { dprint(1, "%s/%d: fast (%dx%d)\n", __func__, VAR_0->qxl.id,
surface_width(VAR_1), surface_height(VAR_1)); qemu_mutex_lock(&VAR_0->lock); VAR_0->ds = VAR_1; pixman_image_unref(VAR_0->VAR_1); VAR_0->VAR_1 = pixman_image_ref(VAR_0->ds->image); qemu_mutex_unlock(&VAR_0->lock); qemu_spice_display_update(VAR_0, 0, 0,
surface_width(VAR_1),
surface_height(VAR_1)); return; } dprint(1, "%s/%d: full (%dx%d -> %dx%d)\n", __func__, VAR_0->qxl.id,
VAR_0->VAR_1 ? pixman_image_get_width(VAR_0->VAR_1)  : 0,
VAR_0->VAR_1 ? pixman_image_get_height(VAR_0->VAR_1) : 0,
VAR_1 ? surface_width(VAR_1)  : 0,
VAR_1 ? surface_height(VAR_1) : 0); memset(&VAR_0->dirty, 0, sizeof(VAR_0->dirty)); if (VAR_0->VAR_1) { pixman_image_unref(VAR_0->VAR_1); VAR_0->VAR_1 = NULL; pixman_image_unref(VAR_0->mirror); VAR_0->mirror = NULL; } qemu_mutex_lock(&VAR_0->lock); need_destroy = (VAR_0->ds != NULL); VAR_0->ds = VAR_1; while ((update = QTAILQ_FIRST(&VAR_0->updates)) != NULL) { QTAILQ_REMOVE(&VAR_0->updates, update, next); qemu_spice_destroy_update(VAR_0, update); } qemu_mutex_unlock(&VAR_0->lock); if (need_destroy) { qemu_spice_destroy_host_primary(VAR_0); } if (VAR_0->ds) { VAR_0->VAR_1 = pixman_image_ref(VAR_0->ds->image); VAR_0->mirror  = qemu_pixman_mirror_create(VAR_0->ds->format,
VAR_0->ds->image); qemu_spice_create_host_primary(VAR_0); } memset(&VAR_0->dirty, 0, sizeof(VAR_0->dirty)); VAR_0->notify++; }