168
173
void vga_hw_screen_dump(const char *filename)
170
/* There is currently no was of specifying which screen we want to dump,
171
so always dump the dirst one. */
175
TextConsole *previous_active_console;
177
previous_active_console = active_console;
178
active_console = consoles[0];
179
/* There is currently no way of specifying which screen we want to dump,
180
so always dump the first one. */
172
181
if (consoles[0]->hw_screen_dump)
173
182
consoles[0]->hw_screen_dump(consoles[0]->hw, filename);
183
active_console = previous_active_console;
176
186
void vga_hw_text_update(console_ch_t *chardata)
260
bpp = (ds->depth + 7) >> 3;
270
bpp = (ds_get_bits_per_pixel(ds) + 7) >> 3;
264
ds->linesize * ys + bpp * xs;
266
ds->linesize * yd + bpp * xd;
273
s = ds_get_data(ds) +
274
ds_get_linesize(ds) * ys + bpp * xs;
275
d = ds_get_data(ds) +
276
ds_get_linesize(ds) * yd + bpp * xd;
267
277
for (y = 0; y < h; y++) {
268
278
memmove(d, s, wb);
279
d += ds_get_linesize(ds);
280
s += ds_get_linesize(ds);
274
ds->linesize * (ys + h - 1) + bpp * xs;
276
ds->linesize * (yd + h - 1) + bpp * xd;
283
s = ds_get_data(ds) +
284
ds_get_linesize(ds) * (ys + h - 1) + bpp * xs;
285
d = ds_get_data(ds) +
286
ds_get_linesize(ds) * (yd + h - 1) + bpp * xd;
277
287
for (y = 0; y < h; y++) {
278
288
memmove(d, s, wb);
289
d -= ds_get_linesize(ds);
290
s -= ds_get_linesize(ds);
531
541
s->text_y[1] = MAX(s->text_y[1], y);
544
static void invalidate_xy(TextConsole *s, int x, int y)
546
if (s->update_x0 > x * FONT_WIDTH)
547
s->update_x0 = x * FONT_WIDTH;
548
if (s->update_y0 > y * FONT_HEIGHT)
549
s->update_y0 = y * FONT_HEIGHT;
550
if (s->update_x1 < (x + 1) * FONT_WIDTH)
551
s->update_x1 = (x + 1) * FONT_WIDTH;
552
if (s->update_y1 < (y + 1) * FONT_HEIGHT)
553
s->update_y1 = (y + 1) * FONT_HEIGHT;
534
556
static void update_xy(TextConsole *s, int x, int y)
539
561
if (s == active_console) {
562
if (!ds_get_bits_per_pixel(s->ds)) {
541
563
text_update_xy(s, x, y);
1050
1082
TextConsole *s = chr->opaque;
1085
s->update_x0 = s->width * FONT_WIDTH;
1086
s->update_y0 = s->height * FONT_HEIGHT;
1053
1089
console_show_cursor(s, 0);
1054
1090
for(i = 0; i < len; i++) {
1055
1091
console_putchar(s, buf[i]);
1057
1093
console_show_cursor(s, 1);
1094
if (ds_get_bits_per_pixel(s->ds) && s->update_x0 < s->update_x1) {
1095
dpy_update(s->ds, s->update_x0, s->update_y0,
1096
s->update_x1 - s->update_x0,
1097
s->update_y1 - s->update_y0);
1148
1189
static void text_console_invalidate(void *opaque)
1150
1191
TextConsole *s = (TextConsole *) opaque;
1152
if (s->console_type != GRAPHIC_CONSOLE) {
1153
if (s->g_width != s->ds->width ||
1154
s->g_height != s->ds->height) {
1155
if (s->console_type == TEXT_CONSOLE_FIXED_SIZE)
1156
dpy_resize(s->ds, s->g_width, s->g_height);
1158
s->g_width = s->ds->width;
1159
s->g_height = s->ds->height;
1160
text_console_resize(s);
1192
if (!ds_get_bits_per_pixel(s->ds) && s->console_type == TEXT_CONSOLE) {
1193
s->g_width = ds_get_width(s->ds);
1194
s->g_height = ds_get_height(s->ds);
1195
text_console_resize(s);
1164
1197
console_refresh(s);
1218
1260
consoles[i] = consoles[i - 1];
1220
1262
consoles[i] = s;
1225
TextConsole *graphic_console_init(DisplayState *ds, vga_hw_update_ptr update,
1226
vga_hw_invalidate_ptr invalidate,
1227
vga_hw_screen_dump_ptr screen_dump,
1228
vga_hw_text_update_ptr text_update,
1268
DisplayState *graphic_console_init(vga_hw_update_ptr update,
1269
vga_hw_invalidate_ptr invalidate,
1270
vga_hw_screen_dump_ptr screen_dump,
1271
vga_hw_text_update_ptr text_update,
1231
1274
TextConsole *s;
1277
ds = (DisplayState *) qemu_mallocz(sizeof(DisplayState));
1278
ds->allocator = &default_allocator;
1279
ds->surface = qemu_create_displaysurface(ds, 640, 480);
1233
1281
s = new_console(ds, GRAPHIC_CONSOLE);
1283
qemu_free_displaysurface(ds);
1236
1287
s->hw_update = update;
1237
1288
s->hw_invalidate = invalidate;
1238
1289
s->hw_screen_dump = screen_dump;
1239
1290
s->hw_text_update = text_update;
1240
1291
s->hw = opaque;
1293
register_displaystate(ds);
1244
1297
int is_graphic_console(void)
1246
1299
return active_console && active_console->console_type == GRAPHIC_CONSOLE;
1302
int is_fixedsize_console(void)
1304
return active_console && active_console->console_type != TEXT_CONSOLE;
1249
1307
void console_color_init(DisplayState *ds)
1252
1310
for (j = 0; j < 2; j++) {
1253
1311
for (i = 0; i < 8; i++) {
1254
color_table[j][i] = col_expand(ds,
1312
color_table[j][i] = col_expand(ds,
1255
1313
vga_get_color(ds, color_table_rgb[j][i]));
1260
CharDriverState *text_console_init(DisplayState *ds, const char *p)
1318
static int n_text_consoles;
1319
static CharDriverState *text_consoles[128];
1320
static char *text_console_strs[128];
1322
static void text_console_do_init(CharDriverState *chr, DisplayState *ds, const char *p)
1262
CharDriverState *chr;
1263
1324
TextConsole *s;
1264
1325
unsigned width;
1265
1326
unsigned height;
1266
1327
static int color_inited;
1268
chr = qemu_mallocz(sizeof(CharDriverState));
1271
s = new_console(ds, (p == 0) ? TEXT_CONSOLE : TEXT_CONSOLE_FIXED_SIZE);
1329
s = new_console(ds, (p == NULL) ? TEXT_CONSOLE : TEXT_CONSOLE_FIXED_SIZE);
1276
1334
chr->opaque = s;
1277
1335
chr->chr_write = console_puts;
1323
1382
s->t_attrib_default.unvisible = 0;
1324
1383
s->t_attrib_default.fgcol = COLOR_WHITE;
1325
1384
s->t_attrib_default.bgcol = COLOR_BLACK;
1327
1385
/* set current text attributes to default */
1328
1386
s->t_attrib = s->t_attrib_default;
1329
1387
text_console_resize(s);
1331
1389
qemu_chr_reset(chr);
1394
CharDriverState *text_console_init(const char *p)
1396
CharDriverState *chr;
1398
chr = qemu_mallocz(sizeof(CharDriverState));
1400
if (n_text_consoles == 128) {
1401
fprintf(stderr, "Too many text consoles\n");
1404
text_consoles[n_text_consoles] = chr;
1405
text_console_strs[n_text_consoles] = p ? qemu_strdup(p) : NULL;
1411
void text_consoles_set_display(DisplayState *ds)
1415
for (i = 0; i < n_text_consoles; i++) {
1416
text_console_do_init(text_consoles[i], ds, text_console_strs[i]);
1417
qemu_free(text_console_strs[i]);
1420
n_text_consoles = 0;
1423
void qemu_console_resize(DisplayState *ds, int width, int height)
1425
TextConsole *s = get_graphic_console(ds);
1429
s->g_height = height;
1430
if (is_graphic_console()) {
1431
ds->surface = qemu_resize_displaysurface(ds, width, height);
1436
void qemu_console_copy(DisplayState *ds, int src_x, int src_y,
1437
int dst_x, int dst_y, int w, int h)
1439
if (is_graphic_console()) {
1440
dpy_copy(ds, src_x, src_y, dst_x, dst_y, w, h);
1444
PixelFormat qemu_different_endianness_pixelformat(int bpp)
1448
memset(&pf, 0x00, sizeof(PixelFormat));
1450
pf.bits_per_pixel = bpp;
1451
pf.bytes_per_pixel = bpp / 8;
1452
pf.depth = bpp == 32 ? 24 : bpp;
1456
pf.rmask = 0x000000FF;
1457
pf.gmask = 0x0000FF00;
1458
pf.bmask = 0x00FF0000;
1470
pf.rmask = 0x0000FF00;
1471
pf.gmask = 0x00FF0000;
1472
pf.bmask = 0xFF000000;
1473
pf.amask = 0x00000000;
1493
PixelFormat qemu_default_pixelformat(int bpp)
1497
memset(&pf, 0x00, sizeof(PixelFormat));
1499
pf.bits_per_pixel = bpp;
1500
pf.bytes_per_pixel = bpp / 8;
1501
pf.depth = bpp == 32 ? 24 : bpp;
1505
pf.rmask = 0x0000F800;
1506
pf.gmask = 0x000007E0;
1507
pf.bmask = 0x0000001F;
1519
pf.rmask = 0x00FF0000;
1520
pf.gmask = 0x0000FF00;
1521
pf.bmask = 0x000000FF;
1532
pf.rmask = 0x00FF0000;
1533
pf.gmask = 0x0000FF00;
1534
pf.bmask = 0x000000FF;
1554
DisplaySurface* defaultallocator_create_displaysurface(int width, int height)
1556
DisplaySurface *surface = (DisplaySurface*) qemu_mallocz(sizeof(DisplaySurface));
1558
surface->width = width;
1559
surface->height = height;
1560
surface->linesize = width * 4;
1561
surface->pf = qemu_default_pixelformat(32);
1562
#ifdef HOST_WORDS_BIGENDIAN
1563
surface->flags = QEMU_ALLOCATED_FLAG | QEMU_BIG_ENDIAN_FLAG;
1565
surface->flags = QEMU_ALLOCATED_FLAG;
1567
surface->data = (uint8_t*) qemu_mallocz(surface->linesize * surface->height);
1572
DisplaySurface* defaultallocator_resize_displaysurface(DisplaySurface *surface,
1573
int width, int height)
1575
surface->width = width;
1576
surface->height = height;
1577
surface->linesize = width * 4;
1578
surface->pf = qemu_default_pixelformat(32);
1579
if (surface->flags & QEMU_ALLOCATED_FLAG)
1580
surface->data = (uint8_t*) qemu_realloc(surface->data, surface->linesize * surface->height);
1582
surface->data = (uint8_t*) qemu_malloc(surface->linesize * surface->height);
1583
#ifdef HOST_WORDS_BIGENDIAN
1584
surface->flags = QEMU_ALLOCATED_FLAG | QEMU_BIG_ENDIAN_FLAG;
1586
surface->flags = QEMU_ALLOCATED_FLAG;
1592
DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp,
1593
int linesize, uint8_t *data)
1595
DisplaySurface *surface = (DisplaySurface*) qemu_mallocz(sizeof(DisplaySurface));
1597
surface->width = width;
1598
surface->height = height;
1599
surface->linesize = linesize;
1600
surface->pf = qemu_default_pixelformat(bpp);
1601
#ifdef HOST_WORDS_BIGENDIAN
1602
surface->flags = QEMU_BIG_ENDIAN_FLAG;
1604
surface->data = data;
1609
void defaultallocator_free_displaysurface(DisplaySurface *surface)
1611
if (surface == NULL)
1613
if (surface->flags & QEMU_ALLOCATED_FLAG)
1614
qemu_free(surface->data);