Commit 2c62f08d authored by Gerd Hoffmann's avatar Gerd Hoffmann
Browse files

console: simplify screendump



Screendumps are alot simpler as we can update non-active
QemuConsoles now.  So we only need to update the QemuConsole
we want write out, then dump the DisplaySurface content into
a ppm file.  Done.

No console switching needed.  No special support code in the
gfx card emulation needed.  Zap it all.  Also move ppm_save
out of the vga code and next to the qmp_screendump function.

For now screen dumping is limited to console #0 (like it used
to be), even though it is dead simple to extend it to other
consoles.  I wanna finish the console cleanup before setting
new qapi interfaces into stone.

Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
Tested-by: default avatarIgor Mitsyanko <i.mitsyanko@gmail.com>
parent 321f048d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -612,7 +612,7 @@ static int musicpal_lcd_init(SysBusDevice *dev)
    sysbus_init_mmio(dev, &s->iomem);

    s->con = graphic_console_init(lcd_refresh, lcd_invalidate,
                                  NULL, NULL, s);
                                  NULL, s);
    qemu_console_resize(s->con, 128*3, 64*3);

    qdev_init_gpio_in(&dev->qdev, musicpal_lcd_gpio_brigthness_in, 3);
+1 −13
Original line number Diff line number Diff line
@@ -933,18 +933,6 @@ static void blizzard_update_display(void *opaque)
    s->my[1] = 0;
}

static void blizzard_screen_dump(void *opaque, const char *filename,
                                 bool cswitch, Error **errp)
{
    BlizzardState *s = (BlizzardState *) opaque;
    DisplaySurface *surface = qemu_console_surface(s->con);

    blizzard_update_display(opaque);
    if (s && surface_data(surface)) {
        ppm_save(filename, surface, errp);
    }
}

#define DEPTH 8
#include "blizzard_template.h"
#define DEPTH 15
@@ -965,7 +953,7 @@ void *s1d13745_init(qemu_irq gpio_int)

    s->con = graphic_console_init(blizzard_update_display,
                                  blizzard_invalidate_display,
                                  blizzard_screen_dump, NULL, s);
                                  NULL, s);
    surface = qemu_console_surface(s->con);

    switch (surface_bits_per_pixel(surface)) {
+2 −2
Original line number Diff line number Diff line
@@ -2911,7 +2911,7 @@ static int vga_initfn(ISADevice *dev)
    cirrus_init_common(&d->cirrus_vga, CIRRUS_ID_CLGD5430, 0,
                       isa_address_space(dev), isa_address_space_io(dev));
    s->con = graphic_console_init(s->update, s->invalidate,
                                  s->screen_dump, s->text_update,
                                  s->text_update,
                                  s);
    rom_add_vga(VGABIOS_CIRRUS_FILENAME);
    /* XXX ISA-LFB support */
@@ -2960,7 +2960,7 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev)
     cirrus_init_common(s, device_id, 1, pci_address_space(dev),
                        pci_address_space_io(dev));
     s->vga.con = graphic_console_init(s->vga.update, s->vga.invalidate,
                                       s->vga.screen_dump, s->vga.text_update,
                                       s->vga.text_update,
                                       &s->vga);

     /* setup PCI */
+1 −1
Original line number Diff line number Diff line
@@ -1901,7 +1901,7 @@ static int exynos4210_fimd_init(SysBusDevice *dev)
            "exynos4210.fimd", FIMD_REGS_SIZE);
    sysbus_init_mmio(dev, &s->iomem);
    s->console = graphic_console_init(exynos4210_fimd_update,
                                  exynos4210_fimd_invalidate, NULL, NULL, s);
                                      exynos4210_fimd_invalidate, NULL, s);

    return 0;
}
+1 −72
Original line number Diff line number Diff line
@@ -294,77 +294,6 @@ static void g364fb_reset(G364State *s)
    g364fb_invalidate_display(s);
}

static void g364fb_screen_dump(void *opaque, const char *filename, bool cswitch,
                               Error **errp)
{
    G364State *s = opaque;
    int ret, y, x;
    uint8_t index;
    uint8_t *data_buffer;
    FILE *f;

    qemu_flush_coalesced_mmio_buffer();

    if (s->depth != 8) {
        error_setg(errp, "g364: unknown guest depth %d", s->depth);
        return;
    }

    f = fopen(filename, "wb");
    if (!f) {
        error_setg(errp, "failed to open file '%s': %s", filename,
                   strerror(errno));
        return;
    }

    if (s->ctla & CTLA_FORCE_BLANK) {
        /* blank screen */
        ret = fprintf(f, "P4\n%d %d\n", s->width, s->height);
        if (ret < 0) {
            goto write_err;
        }
        for (y = 0; y < s->height; y++)
            for (x = 0; x < s->width; x++) {
                ret = fputc(0, f);
                if (ret == EOF) {
                    goto write_err;
                }
            }
    } else {
        data_buffer = s->vram + s->top_of_screen;
        ret = fprintf(f, "P6\n%d %d\n%d\n", s->width, s->height, 255);
        if (ret < 0) {
            goto write_err;
        }
        for (y = 0; y < s->height; y++)
            for (x = 0; x < s->width; x++, data_buffer++) {
                index = *data_buffer;
                ret = fputc(s->color_palette[index][0], f);
                if (ret == EOF) {
                    goto write_err;
                }
                ret = fputc(s->color_palette[index][1], f);
                if (ret == EOF) {
                    goto write_err;
                }
                ret = fputc(s->color_palette[index][2], f);
                if (ret == EOF) {
                    goto write_err;
                }
        }
    }

out:
    fclose(f);
    return;

write_err:
    error_setg(errp, "failed to write to file '%s': %s", filename,
               strerror(errno));
    unlink(filename);
    goto out;
}

/* called for accesses to io ports */
static uint64_t g364fb_ctrl_read(void *opaque,
                                 hwaddr addr,
@@ -552,7 +481,7 @@ static void g364fb_init(DeviceState *dev, G364State *s)

    s->con = graphic_console_init(g364fb_update_display,
                                  g364fb_invalidate_display,
                                  g364fb_screen_dump, NULL, s);
                                  NULL, s);

    memory_region_init_io(&s->mem_ctrl, &g364fb_ctrl_ops, s, "ctrl", 0x180000);
    memory_region_init_ram_ptr(&s->mem_vram, "vram",
Loading