Revision 2c62f08d hw/display/vga.c

b/hw/display/vga.c
166 166
static uint16_t expand2[256];
167 167
static uint8_t expand4to8[16];
168 168

  
169
static void vga_screen_dump(void *opaque, const char *filename, bool cswitch,
170
                            Error **errp);
171

  
172 169
static void vga_update_memory_access(VGACommonState *s)
173 170
{
174 171
    MemoryRegion *region, *old_region = s->chain4_alias;
......
2298 2295
    s->get_resolution = vga_get_resolution;
2299 2296
    s->update = vga_update_display;
2300 2297
    s->invalidate = vga_invalidate_display;
2301
    s->screen_dump = vga_screen_dump;
2302 2298
    s->text_update = vga_update_text;
2303 2299
    switch (vga_retrace_method) {
2304 2300
    case VGA_RETRACE_DUMB:
......
2393 2389
                                &s->vram_vbe);
2394 2390
    s->vbe_mapped = 1;
2395 2391
}
2396
/********************************************************/
2397
/* vga screen dump */
2398

  
2399
void ppm_save(const char *filename, struct DisplaySurface *ds, Error **errp)
2400
{
2401
    int width = pixman_image_get_width(ds->image);
2402
    int height = pixman_image_get_height(ds->image);
2403
    FILE *f;
2404
    int y;
2405
    int ret;
2406
    pixman_image_t *linebuf;
2407

  
2408
    trace_ppm_save(filename, ds);
2409
    f = fopen(filename, "wb");
2410
    if (!f) {
2411
        error_setg(errp, "failed to open file '%s': %s", filename,
2412
                   strerror(errno));
2413
        return;
2414
    }
2415
    ret = fprintf(f, "P6\n%d %d\n%d\n", width, height, 255);
2416
    if (ret < 0) {
2417
        linebuf = NULL;
2418
        goto write_err;
2419
    }
2420
    linebuf = qemu_pixman_linebuf_create(PIXMAN_BE_r8g8b8, width);
2421
    for (y = 0; y < height; y++) {
2422
        qemu_pixman_linebuf_fill(linebuf, ds->image, width, 0, y);
2423
        clearerr(f);
2424
        ret = fwrite(pixman_image_get_data(linebuf), 1,
2425
                     pixman_image_get_stride(linebuf), f);
2426
        (void)ret;
2427
        if (ferror(f)) {
2428
            goto write_err;
2429
        }
2430
    }
2431

  
2432
out:
2433
    qemu_pixman_image_unref(linebuf);
2434
    fclose(f);
2435
    return;
2436

  
2437
write_err:
2438
    error_setg(errp, "failed to write to file '%s': %s", filename,
2439
               strerror(errno));
2440
    unlink(filename);
2441
    goto out;
2442
}
2443

  
2444
/* save the vga display in a PPM image even if no display is
2445
   available */
2446
static void vga_screen_dump(void *opaque, const char *filename, bool cswitch,
2447
                            Error **errp)
2448
{
2449
    VGACommonState *s = opaque;
2450
    DisplaySurface *surface = qemu_console_surface(s->con);
2451

  
2452
    if (cswitch) {
2453
        vga_invalidate_display(s);
2454
    }
2455
    graphic_hw_update(s->con);
2456
    ppm_save(filename, surface, errp);
2457
}

Also available in: Unified diff