Revision 187cd1d9 console.c

b/console.c
1294 1294
    return s;
1295 1295
}
1296 1296

  
1297
static DisplaySurface* defaultallocator_create_displaysurface(int width, int height)
1297
DisplaySurface *qemu_create_displaysurface(DisplayState *ds,
1298
                                           int width, int height)
1298 1299
{
1299
    DisplaySurface *surface = (DisplaySurface*) g_malloc0(sizeof(DisplaySurface));
1300
    DisplaySurface *surface = g_new0(DisplaySurface, 1);
1300 1301

  
1301 1302
    int linesize = width * 4;
1302 1303
    qemu_alloc_display(surface, width, height, linesize,
......
1304 1305
    return surface;
1305 1306
}
1306 1307

  
1307
static DisplaySurface* defaultallocator_resize_displaysurface(DisplaySurface *surface,
1308
                                          int width, int height)
1308
DisplaySurface *qemu_resize_displaysurface(DisplayState *ds,
1309
                                           int width, int height)
1309 1310
{
1310 1311
    int linesize = width * 4;
1311
    qemu_alloc_display(surface, width, height, linesize,
1312

  
1313
    trace_displaysurface_resize(ds, ds->surface, width, height);
1314
    qemu_alloc_display(ds->surface, width, height, linesize,
1312 1315
                       qemu_default_pixelformat(32), 0);
1313
    return surface;
1316
    return ds->surface;
1314 1317
}
1315 1318

  
1316 1319
void qemu_alloc_display(DisplaySurface *surface, int width, int height,
......
1323 1326
    surface->pf = pf;
1324 1327
    if (surface->flags & QEMU_ALLOCATED_FLAG) {
1325 1328
        data = g_realloc(surface->data,
1326
                            surface->linesize * surface->height);
1329
                         surface->linesize * surface->height);
1327 1330
    } else {
1328 1331
        data = g_malloc(surface->linesize * surface->height);
1329 1332
    }
......
1334 1337
#endif
1335 1338
}
1336 1339

  
1337
DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp,
1340
DisplaySurface *qemu_create_displaysurface_from(int width, int height, int bpp,
1338 1341
                                              int linesize, uint8_t *data)
1339 1342
{
1340 1343
    DisplaySurface *surface = (DisplaySurface*) g_malloc0(sizeof(DisplaySurface));
......
1351 1354
    return surface;
1352 1355
}
1353 1356

  
1354
static void defaultallocator_free_displaysurface(DisplaySurface *surface)
1357
void qemu_free_displaysurface(DisplayState *ds)
1355 1358
{
1356
    if (surface == NULL)
1359
    trace_displaysurface_free(ds, ds->surface);
1360
    if (ds->surface == NULL) {
1357 1361
        return;
1358
    if (surface->flags & QEMU_ALLOCATED_FLAG)
1359
        g_free(surface->data);
1360
    g_free(surface);
1362
    }
1363
    if (ds->surface->flags & QEMU_ALLOCATED_FLAG) {
1364
        g_free(ds->surface->data);
1365
    }
1366
    g_free(ds->surface);
1361 1367
}
1362 1368

  
1363
static struct DisplayAllocator default_allocator = {
1364
    defaultallocator_create_displaysurface,
1365
    defaultallocator_resize_displaysurface,
1366
    defaultallocator_free_displaysurface
1367
};
1368

  
1369 1369
static void dumb_display_init(void)
1370 1370
{
1371 1371
    DisplayState *ds = g_malloc0(sizeof(DisplayState));
1372 1372
    int width = 640;
1373 1373
    int height = 480;
1374 1374

  
1375
    ds->allocator = &default_allocator;
1376 1375
    if (is_fixedsize_console()) {
1377 1376
        width = active_console->g_width;
1378 1377
        height = active_console->g_height;
......
1402 1401
    return display_state;
1403 1402
}
1404 1403

  
1405
DisplayAllocator *register_displayallocator(DisplayState *ds, DisplayAllocator *da)
1406
{
1407
    if(ds->allocator ==  &default_allocator) {
1408
        DisplaySurface *surf;
1409
        surf = da->create_displaysurface(ds_get_width(ds), ds_get_height(ds));
1410
        defaultallocator_free_displaysurface(ds->surface);
1411
        ds->surface = surf;
1412
        ds->allocator = da;
1413
    }
1414
    return ds->allocator;
1415
}
1416

  
1417 1404
DisplayState *graphic_console_init(vga_hw_update_ptr update,
1418 1405
                                   vga_hw_invalidate_ptr invalidate,
1419 1406
                                   vga_hw_screen_dump_ptr screen_dump,
......
1424 1411
    DisplayState *ds;
1425 1412

  
1426 1413
    ds = (DisplayState *) g_malloc0(sizeof(DisplayState));
1427
    ds->allocator = &default_allocator; 
1428 1414
    ds->surface = qemu_create_displaysurface(ds, 640, 480);
1429 1415

  
1430 1416
    s = new_console(ds, GRAPHIC_CONSOLE);

Also available in: Unified diff