void dpy_gfx_update_dirty(QemuConsole *con,

                          MemoryRegion *address_space,

                          hwaddr base,

                          bool invalidate)

{

    DisplaySurface *ds = qemu_console_surface(con);

    int width = surface_stride(ds);

    int height = surface_height(ds);

    hwaddr size = width * height;

    MemoryRegionSection mem_section;

    MemoryRegion *mem;

    ram_addr_t addr;

    int first, last, i;

    bool dirty;



    mem_section = memory_region_find(address_space, base, size);

    mem = mem_section.mr;

    if (int128_get64(mem_section.size) != size ||

        !memory_region_is_ram(mem_section.mr)) {

        goto out;

    }

    assert(mem);



    memory_region_sync_dirty_bitmap(mem);

    addr = mem_section.offset_within_region;



    first = -1;

    last = -1;

    for (i = 0; i < height; i++, addr += width) {

        dirty = invalidate ||

            memory_region_get_dirty(mem, addr, width, DIRTY_MEMORY_VGA);

        if (dirty) {

            if (first == -1) {

                first = i;

            }

            last = i;

        }

        if (first != -1 && !dirty) {

            assert(last != -1 && last >= first);

            dpy_gfx_update(con, 0, first, surface_width(ds),

                           last - first + 1);

            first = -1;

        }

    }

    if (first != -1) {

        assert(last != -1 && last >= first);

        dpy_gfx_update(con, 0, first, surface_width(ds),

                       last - first + 1);

    }



    memory_region_reset_dirty(mem, mem_section.offset_within_region, size,

                              DIRTY_MEMORY_VGA);

out:

    memory_region_unref(mem);

}

void dpy_gfx_update_dirty(QemuConsole *con,

                          MemoryRegion *address_space,

                          hwaddr base,

                          bool invalidate)

{

    DisplaySurface *ds = qemu_console_surface(con);

    int width = surface_stride(ds);

    int height = surface_height(ds);

    hwaddr size = width * height;

    MemoryRegionSection mem_section;

    MemoryRegion *mem;

    ram_addr_t addr;

    int first, last, i;

    bool dirty;



    mem_section = memory_region_find(address_space, base, size);

    mem = mem_section.mr;

    if (int128_get64(mem_section.size) != size ||

        !memory_region_is_ram(mem_section.mr)) {

        goto out;

    }

    assert(mem);



    memory_region_sync_dirty_bitmap(mem);

    addr = mem_section.offset_within_region;



    first = -1;

    last = -1;

    for (i = 0; i < height; i++, addr += width) {

        dirty = invalidate ||

            memory_region_get_dirty(mem, addr, width, DIRTY_MEMORY_VGA);

        if (dirty) {

            if (first == -1) {

                first = i;

            }

            last = i;

        }

        if (first != -1 && !dirty) {

            assert(last != -1 && last >= first);

            dpy_gfx_update(con, 0, first, surface_width(ds),

                           last - first + 1);

            first = -1;

        }

    }

    if (first != -1) {

        assert(last != -1 && last >= first);

        dpy_gfx_update(con, 0, first, surface_width(ds),

                       last - first + 1);

    }



    memory_region_reset_dirty(mem, mem_section.offset_within_region, size,

                              DIRTY_MEMORY_VGA);

out:

    memory_region_unref(mem);

}

void FUNC_0(QemuConsole *VAR_0,

                          MemoryRegion *VAR_1,

                          hwaddr VAR_2,

                          bool VAR_3)

{

    DisplaySurface *ds = qemu_console_surface(VAR_0);

    int VAR_4 = surface_stride(ds);

    int VAR_5 = surface_height(ds);

    hwaddr size = VAR_4 * VAR_5;

    MemoryRegionSection mem_section;

    MemoryRegion *mem;

    ram_addr_t addr;

    int VAR_6, VAR_7, VAR_8;

    bool dirty;



    mem_section = memory_region_find(VAR_1, VAR_2, size);

    mem = mem_section.mr;

    if (int128_get64(mem_section.size) != size ||

        !memory_region_is_ram(mem_section.mr)) {

        goto out;

    }

    assert(mem);



    memory_region_sync_dirty_bitmap(mem);

    addr = mem_section.offset_within_region;



    VAR_6 = -1;

    VAR_7 = -1;

    for (VAR_8 = 0; VAR_8 < VAR_5; VAR_8++, addr += VAR_4) {

        dirty = VAR_3 ||

            memory_region_get_dirty(mem, addr, VAR_4, DIRTY_MEMORY_VGA);

        if (dirty) {

            if (VAR_6 == -1) {

                VAR_6 = VAR_8;

            }

            VAR_7 = VAR_8;

        }

        if (VAR_6 != -1 && !dirty) {

            assert(VAR_7 != -1 && VAR_7 >= VAR_6);

            dpy_gfx_update(VAR_0, 0, VAR_6, surface_width(ds),

                           VAR_7 - VAR_6 + 1);

            VAR_6 = -1;

        }

    }

    if (VAR_6 != -1) {

        assert(VAR_7 != -1 && VAR_7 >= VAR_6);

        dpy_gfx_update(VAR_0, 0, VAR_6, surface_width(ds),

                       VAR_7 - VAR_6 + 1);

    }



    memory_region_reset_dirty(mem, mem_section.offset_within_region, size,

                              DIRTY_MEMORY_VGA);

out:

    memory_region_unref(mem);

}

void FUNC_0(QemuConsole *VAR_0,
MemoryRegion *VAR_1,
hwaddr VAR_2,
bool VAR_3)
{ DisplaySurface *ds = qemu_console_surface(VAR_0); int VAR_4 = surface_stride(ds); int VAR_5 = surface_height(ds); hwaddr size = VAR_4 * VAR_5; MemoryRegionSection mem_section; MemoryRegion *mem; ram_addr_t addr; int VAR_6, VAR_7, VAR_8; bool dirty; mem_section = memory_region_find(VAR_1, VAR_2, size); mem = mem_section.mr; if (int128_get64(mem_section.size) != size ||
!memory_region_is_ram(mem_section.mr)) { goto out; } assert(mem); memory_region_sync_dirty_bitmap(mem); addr = mem_section.offset_within_region; VAR_6 = -1; VAR_7 = -1; for (VAR_8 = 0; VAR_8 < VAR_5; VAR_8++, addr += VAR_4) { dirty = VAR_3 ||
memory_region_get_dirty(mem, addr, VAR_4, DIRTY_MEMORY_VGA); if (dirty) { if (VAR_6 == -1) { VAR_6 = VAR_8; } VAR_7 = VAR_8; } if (VAR_6 != -1 && !dirty) { assert(VAR_7 != -1 && VAR_7 >= VAR_6); dpy_gfx_update(VAR_0, 0, VAR_6, surface_width(ds),
VAR_7 - VAR_6 + 1); VAR_6 = -1; } } if (VAR_6 != -1) { assert(VAR_7 != -1 && VAR_7 >= VAR_6); dpy_gfx_update(VAR_0, 0, VAR_6, surface_width(ds),
VAR_7 - VAR_6 + 1); } memory_region_reset_dirty(mem, mem_section.offset_within_region, size,
DIRTY_MEMORY_VGA); out:
memory_region_unref(mem); }