summaryrefslogtreecommitdiffstats
path: root/backends/msmouse.c
diff options
context:
space:
mode:
authorMarc-André Lureau2016-10-21 22:44:44 +0200
committerPaolo Bonzini2017-01-27 18:07:59 +0100
commit41ac54b253f41df924c350ef63564df8e1d8ad88 (patch)
treea6d8fdcb913b558c4f5ecc698bd82ae1a195705c /backends/msmouse.c
parentchar: use a feature bit for replay (diff)
downloadqemu-41ac54b253f41df924c350ef63564df8e1d8ad88.tar.gz
qemu-41ac54b253f41df924c350ef63564df8e1d8ad88.tar.xz
qemu-41ac54b253f41df924c350ef63564df8e1d8ad88.zip
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>
Diffstat (limited to 'backends/msmouse.c')
-rw-r--r--backends/msmouse.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/backends/msmouse.c b/backends/msmouse.c
index 2c238ba1b3..30087b358f 100644
--- a/backends/msmouse.c
+++ b/backends/msmouse.c
@@ -31,7 +31,8 @@
#define MSMOUSE_HI2(n) (((n) & 0xc0) >> 6)
typedef struct {
- CharDriverState *chr;
+ CharDriverState parent;
+
QemuInputHandlerState *hs;
int axis[INPUT_AXIS__MAX];
bool btns[INPUT_BUTTON__MAX];
@@ -42,7 +43,7 @@ typedef struct {
static void msmouse_chr_accept_input(CharDriverState *chr)
{
- MouseState *mouse = chr->opaque;
+ MouseState *mouse = (MouseState *)chr;
int len;
len = qemu_chr_be_can_write(chr);
@@ -122,9 +123,10 @@ static void msmouse_input_event(DeviceState *dev, QemuConsole *src,
static void msmouse_input_sync(DeviceState *dev)
{
MouseState *mouse = (MouseState *)dev;
+ CharDriverState *chr = (CharDriverState *)dev;
msmouse_queue_event(mouse);
- msmouse_chr_accept_input(mouse->chr);
+ msmouse_chr_accept_input(chr);
}
static int msmouse_chr_write (struct CharDriverState *s, const uint8_t *buf, int len)
@@ -135,10 +137,9 @@ static int msmouse_chr_write (struct CharDriverState *s, const uint8_t *buf, int
static void msmouse_chr_free(struct CharDriverState *chr)
{
- MouseState *mouse = chr->opaque;
+ MouseState *mouse = (MouseState *)chr;
qemu_input_handler_unregister(mouse->hs);
- g_free(mouse);
}
static QemuInputHandler msmouse_handler = {
@@ -165,12 +166,10 @@ static CharDriverState *qemu_chr_open_msmouse(const CharDriver *driver,
}
*be_opened = false;
- mouse = g_new0(MouseState, 1);
+ mouse = (MouseState *)chr;
mouse->hs = qemu_input_handler_register((DeviceState *)mouse,
&msmouse_handler);
- mouse->chr = chr;
- chr->opaque = mouse;
return chr;
}
@@ -178,6 +177,7 @@ static CharDriverState *qemu_chr_open_msmouse(const CharDriver *driver,
static void register_types(void)
{
static const CharDriver driver = {
+ .instance_size = sizeof(MouseState),
.kind = CHARDEV_BACKEND_KIND_MSMOUSE,
.create = qemu_chr_open_msmouse,
.chr_write = msmouse_chr_write,