mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 08:13:54 -06:00
char: allocate CharDriverState as a single object
Use a single allocation for CharDriverState, this avoids extra allocations & pointers, and is a step towards more object-oriented CharDriver. Gtk console is a bit peculiar, gd_vc_chr_set_echo() used to have a temporary VirtualConsole to save the echo bit. Instead now, we consider whether vcd->console is set or not, and restore the echo bit saved in VCDriverState when calling gd_vc_vte_init(). The casts added are temporary, they are replaced with QOM type-safe macros in a later patch in this series. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
5ebd67030c
commit
41ac54b253
10 changed files with 230 additions and 214 deletions
21
ui/console.c
21
ui/console.c
|
@ -1046,9 +1046,15 @@ void console_select(unsigned int index)
|
|||
}
|
||||
}
|
||||
|
||||
typedef struct VCDriverState {
|
||||
CharDriverState parent;
|
||||
QemuConsole *console;
|
||||
} VCDriverState;
|
||||
|
||||
static int console_puts(CharDriverState *chr, const uint8_t *buf, int len)
|
||||
{
|
||||
QemuConsole *s = chr->opaque;
|
||||
VCDriverState *drv = (VCDriverState *)chr;
|
||||
QemuConsole *s = drv->console;
|
||||
int i;
|
||||
|
||||
if (!s->ds) {
|
||||
|
@ -1958,7 +1964,8 @@ int qemu_console_get_height(QemuConsole *con, int fallback)
|
|||
|
||||
static void text_console_set_echo(CharDriverState *chr, bool echo)
|
||||
{
|
||||
QemuConsole *s = chr->opaque;
|
||||
VCDriverState *drv = (VCDriverState *)chr;
|
||||
QemuConsole *s = drv->console;
|
||||
|
||||
s->echo = echo;
|
||||
}
|
||||
|
@ -1998,12 +2005,11 @@ static const GraphicHwOps text_console_ops = {
|
|||
|
||||
static void text_console_do_init(CharDriverState *chr, DisplayState *ds)
|
||||
{
|
||||
QemuConsole *s;
|
||||
VCDriverState *drv = (VCDriverState *)chr;
|
||||
QemuConsole *s = drv->console;
|
||||
int g_width = 80 * FONT_WIDTH;
|
||||
int g_height = 24 * FONT_HEIGHT;
|
||||
|
||||
s = chr->opaque;
|
||||
|
||||
s->out_fifo.buf = s->out_fifo_buf;
|
||||
s->out_fifo.buf_size = sizeof(s->out_fifo_buf);
|
||||
s->kbd_timer = timer_new_ms(QEMU_CLOCK_REALTIME, kbd_send_chars, s);
|
||||
|
@ -2056,6 +2062,7 @@ static CharDriverState *text_console_init(ChardevVC *vc, Error **errp)
|
|||
{
|
||||
ChardevCommon *common = qapi_ChardevVC_base(vc);
|
||||
CharDriverState *chr;
|
||||
VCDriverState *drv;
|
||||
QemuConsole *s;
|
||||
unsigned width = 0;
|
||||
unsigned height = 0;
|
||||
|
@ -2092,7 +2099,8 @@ static CharDriverState *text_console_init(ChardevVC *vc, Error **errp)
|
|||
}
|
||||
|
||||
s->chr = chr;
|
||||
chr->opaque = s;
|
||||
drv = (VCDriverState *)chr;
|
||||
drv->console = s;
|
||||
|
||||
if (display_state) {
|
||||
text_console_do_init(chr, display_state);
|
||||
|
@ -2196,6 +2204,7 @@ static const TypeInfo qemu_console_info = {
|
|||
};
|
||||
|
||||
static const CharDriver vc_driver = {
|
||||
.instance_size = sizeof(VCDriverState),
|
||||
.kind = CHARDEV_BACKEND_KIND_VC,
|
||||
.parse = qemu_chr_parse_vc,
|
||||
.create = vc_init,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue