console: kill DisplayState->opaque
It's broken by design. There can be multiple DisplayChangeListener instances, so they simply can't store state in the (single) DisplayState struct. Try 'qemu -display gtk -vnc :0', watch it crash & burn. With DisplayChangeListenerOps having a more sane interface now we can simply use the DisplayChangeListener pointer to get access to our private data instead. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
parent
7c20b4a374
commit
21ef45d712
@ -193,7 +193,6 @@ struct DisplayChangeListener {
|
|||||||
|
|
||||||
struct DisplayState {
|
struct DisplayState {
|
||||||
struct DisplaySurface *surface;
|
struct DisplaySurface *surface;
|
||||||
void *opaque;
|
|
||||||
struct QEMUTimer *gui_timer;
|
struct QEMUTimer *gui_timer;
|
||||||
bool have_gfx;
|
bool have_gfx;
|
||||||
bool have_text;
|
bool have_text;
|
||||||
|
5
ui/gtk.c
5
ui/gtk.c
@ -230,7 +230,7 @@ static void gd_update_caption(GtkDisplayState *s)
|
|||||||
static void gd_update(DisplayChangeListener *dcl,
|
static void gd_update(DisplayChangeListener *dcl,
|
||||||
DisplayState *ds, int x, int y, int w, int h)
|
DisplayState *ds, int x, int y, int w, int h)
|
||||||
{
|
{
|
||||||
GtkDisplayState *s = ds->opaque;
|
GtkDisplayState *s = container_of(dcl, GtkDisplayState, dcl);
|
||||||
int x1, x2, y1, y2;
|
int x1, x2, y1, y2;
|
||||||
int mx, my;
|
int mx, my;
|
||||||
int fbw, fbh;
|
int fbw, fbh;
|
||||||
@ -269,7 +269,7 @@ static void gd_refresh(DisplayChangeListener *dcl,
|
|||||||
static void gd_resize(DisplayChangeListener *dcl,
|
static void gd_resize(DisplayChangeListener *dcl,
|
||||||
DisplayState *ds)
|
DisplayState *ds)
|
||||||
{
|
{
|
||||||
GtkDisplayState *s = ds->opaque;
|
GtkDisplayState *s = container_of(dcl, GtkDisplayState, dcl);
|
||||||
cairo_format_t kind;
|
cairo_format_t kind;
|
||||||
int stride;
|
int stride;
|
||||||
|
|
||||||
@ -1297,7 +1297,6 @@ void gtk_display_init(DisplayState *ds)
|
|||||||
|
|
||||||
gtk_init(NULL, NULL);
|
gtk_init(NULL, NULL);
|
||||||
|
|
||||||
ds->opaque = s;
|
|
||||||
s->ds = ds;
|
s->ds = ds;
|
||||||
s->dcl.ops = &dcl_ops;
|
s->dcl.ops = &dcl_ops;
|
||||||
|
|
||||||
|
38
ui/vnc.c
38
ui/vnc.c
@ -44,7 +44,6 @@ static const struct timeval VNC_REFRESH_LOSSY = { 2, 0 };
|
|||||||
#include "d3des.h"
|
#include "d3des.h"
|
||||||
|
|
||||||
static VncDisplay *vnc_display; /* needed for info vnc */
|
static VncDisplay *vnc_display; /* needed for info vnc */
|
||||||
static DisplayChangeListener *dcl;
|
|
||||||
|
|
||||||
static int vnc_cursor_define(VncState *vs);
|
static int vnc_cursor_define(VncState *vs);
|
||||||
static void vnc_release_modifiers(VncState *vs);
|
static void vnc_release_modifiers(VncState *vs);
|
||||||
@ -435,7 +434,7 @@ static void vnc_dpy_update(DisplayChangeListener *dcl,
|
|||||||
int x, int y, int w, int h)
|
int x, int y, int w, int h)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
VncDisplay *vd = ds->opaque;
|
VncDisplay *vd = container_of(dcl, VncDisplay, dcl);
|
||||||
struct VncSurface *s = &vd->guest;
|
struct VncSurface *s = &vd->guest;
|
||||||
int width = ds_get_width(ds);
|
int width = ds_get_width(ds);
|
||||||
int height = ds_get_height(ds);
|
int height = ds_get_height(ds);
|
||||||
@ -578,7 +577,7 @@ void *vnc_server_fb_ptr(VncDisplay *vd, int x, int y)
|
|||||||
static void vnc_dpy_resize(DisplayChangeListener *dcl,
|
static void vnc_dpy_resize(DisplayChangeListener *dcl,
|
||||||
DisplayState *ds)
|
DisplayState *ds)
|
||||||
{
|
{
|
||||||
VncDisplay *vd = ds->opaque;
|
VncDisplay *vd = container_of(dcl, VncDisplay, dcl);
|
||||||
VncState *vs;
|
VncState *vs;
|
||||||
|
|
||||||
vnc_abort_display_jobs(vd);
|
vnc_abort_display_jobs(vd);
|
||||||
@ -743,7 +742,7 @@ static void vnc_dpy_copy(DisplayChangeListener *dcl,
|
|||||||
int src_x, int src_y,
|
int src_x, int src_y,
|
||||||
int dst_x, int dst_y, int w, int h)
|
int dst_x, int dst_y, int w, int h)
|
||||||
{
|
{
|
||||||
VncDisplay *vd = ds->opaque;
|
VncDisplay *vd = container_of(dcl, VncDisplay, dcl);
|
||||||
VncState *vs, *vn;
|
VncState *vs, *vn;
|
||||||
uint8_t *src_row;
|
uint8_t *src_row;
|
||||||
uint8_t *dst_row;
|
uint8_t *dst_row;
|
||||||
@ -1069,7 +1068,7 @@ void vnc_disconnect_finish(VncState *vs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (QTAILQ_EMPTY(&vs->vd->clients)) {
|
if (QTAILQ_EMPTY(&vs->vd->clients)) {
|
||||||
dcl->idle = 1;
|
vs->vd->dcl.idle = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
vnc_remove_timer(vs->vd);
|
vnc_remove_timer(vs->vd);
|
||||||
@ -1985,7 +1984,7 @@ static void pixel_format_message (VncState *vs) {
|
|||||||
static void vnc_dpy_setdata(DisplayChangeListener *dcl,
|
static void vnc_dpy_setdata(DisplayChangeListener *dcl,
|
||||||
DisplayState *ds)
|
DisplayState *ds)
|
||||||
{
|
{
|
||||||
VncDisplay *vd = ds->opaque;
|
VncDisplay *vd = container_of(dcl, VncDisplay, dcl);
|
||||||
|
|
||||||
qemu_pixman_image_unref(vd->guest.fb);
|
qemu_pixman_image_unref(vd->guest.fb);
|
||||||
vd->guest.fb = pixman_image_ref(ds->surface->image);
|
vd->guest.fb = pixman_image_ref(ds->surface->image);
|
||||||
@ -2697,7 +2696,7 @@ static void vnc_init_timer(VncDisplay *vd)
|
|||||||
vd->timer_interval = VNC_REFRESH_INTERVAL_BASE;
|
vd->timer_interval = VNC_REFRESH_INTERVAL_BASE;
|
||||||
if (vd->timer == NULL && !QTAILQ_EMPTY(&vd->clients)) {
|
if (vd->timer == NULL && !QTAILQ_EMPTY(&vd->clients)) {
|
||||||
vd->timer = qemu_new_timer_ms(rt_clock, vnc_refresh, vd);
|
vd->timer = qemu_new_timer_ms(rt_clock, vnc_refresh, vd);
|
||||||
vnc_dpy_resize(dcl, vd->ds);
|
vnc_dpy_resize(&vd->dcl, vd->ds);
|
||||||
vnc_refresh(vd);
|
vnc_refresh(vd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2736,7 +2735,7 @@ static void vnc_connect(VncDisplay *vd, int csock, int skipauth, bool websocket)
|
|||||||
}
|
}
|
||||||
|
|
||||||
VNC_DEBUG("New client on socket %d\n", csock);
|
VNC_DEBUG("New client on socket %d\n", csock);
|
||||||
dcl->idle = 0;
|
vd->dcl.idle = 0;
|
||||||
socket_set_nonblock(vs->csock);
|
socket_set_nonblock(vs->csock);
|
||||||
#ifdef CONFIG_VNC_WS
|
#ifdef CONFIG_VNC_WS
|
||||||
if (websocket) {
|
if (websocket) {
|
||||||
@ -2847,10 +2846,7 @@ void vnc_display_init(DisplayState *ds)
|
|||||||
{
|
{
|
||||||
VncDisplay *vs = g_malloc0(sizeof(*vs));
|
VncDisplay *vs = g_malloc0(sizeof(*vs));
|
||||||
|
|
||||||
dcl = g_malloc0(sizeof(DisplayChangeListener));
|
vs->dcl.idle = 1;
|
||||||
|
|
||||||
ds->opaque = vs;
|
|
||||||
dcl->idle = 1;
|
|
||||||
vnc_display = vs;
|
vnc_display = vs;
|
||||||
|
|
||||||
vs->lsock = -1;
|
vs->lsock = -1;
|
||||||
@ -2873,14 +2869,14 @@ void vnc_display_init(DisplayState *ds)
|
|||||||
qemu_mutex_init(&vs->mutex);
|
qemu_mutex_init(&vs->mutex);
|
||||||
vnc_start_worker_thread();
|
vnc_start_worker_thread();
|
||||||
|
|
||||||
dcl->ops = &dcl_ops;
|
vs->dcl.ops = &dcl_ops;
|
||||||
register_displaychangelistener(ds, dcl);
|
register_displaychangelistener(ds, &vs->dcl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void vnc_display_close(DisplayState *ds)
|
static void vnc_display_close(DisplayState *ds)
|
||||||
{
|
{
|
||||||
VncDisplay *vs = ds ? (VncDisplay *)ds->opaque : vnc_display;
|
VncDisplay *vs = vnc_display;
|
||||||
|
|
||||||
if (!vs)
|
if (!vs)
|
||||||
return;
|
return;
|
||||||
@ -2911,7 +2907,7 @@ static void vnc_display_close(DisplayState *ds)
|
|||||||
|
|
||||||
static int vnc_display_disable_login(DisplayState *ds)
|
static int vnc_display_disable_login(DisplayState *ds)
|
||||||
{
|
{
|
||||||
VncDisplay *vs = ds ? (VncDisplay *)ds->opaque : vnc_display;
|
VncDisplay *vs = vnc_display;
|
||||||
|
|
||||||
if (!vs) {
|
if (!vs) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -2931,7 +2927,7 @@ static int vnc_display_disable_login(DisplayState *ds)
|
|||||||
|
|
||||||
int vnc_display_password(DisplayState *ds, const char *password)
|
int vnc_display_password(DisplayState *ds, const char *password)
|
||||||
{
|
{
|
||||||
VncDisplay *vs = ds ? (VncDisplay *)ds->opaque : vnc_display;
|
VncDisplay *vs = vnc_display;
|
||||||
|
|
||||||
if (!vs) {
|
if (!vs) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@ -2957,7 +2953,7 @@ int vnc_display_password(DisplayState *ds, const char *password)
|
|||||||
|
|
||||||
int vnc_display_pw_expire(DisplayState *ds, time_t expires)
|
int vnc_display_pw_expire(DisplayState *ds, time_t expires)
|
||||||
{
|
{
|
||||||
VncDisplay *vs = ds ? (VncDisplay *)ds->opaque : vnc_display;
|
VncDisplay *vs = vnc_display;
|
||||||
|
|
||||||
if (!vs) {
|
if (!vs) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@ -2969,14 +2965,14 @@ int vnc_display_pw_expire(DisplayState *ds, time_t expires)
|
|||||||
|
|
||||||
char *vnc_display_local_addr(DisplayState *ds)
|
char *vnc_display_local_addr(DisplayState *ds)
|
||||||
{
|
{
|
||||||
VncDisplay *vs = ds ? (VncDisplay *)ds->opaque : vnc_display;
|
VncDisplay *vs = vnc_display;
|
||||||
|
|
||||||
return vnc_socket_local_addr("%s:%s", vs->lsock);
|
return vnc_socket_local_addr("%s:%s", vs->lsock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vnc_display_open(DisplayState *ds, const char *display, Error **errp)
|
void vnc_display_open(DisplayState *ds, const char *display, Error **errp)
|
||||||
{
|
{
|
||||||
VncDisplay *vs = ds ? (VncDisplay *)ds->opaque : vnc_display;
|
VncDisplay *vs = vnc_display;
|
||||||
const char *options;
|
const char *options;
|
||||||
int password = 0;
|
int password = 0;
|
||||||
int reverse = 0;
|
int reverse = 0;
|
||||||
@ -3282,7 +3278,7 @@ fail:
|
|||||||
|
|
||||||
void vnc_display_add_client(DisplayState *ds, int csock, int skipauth)
|
void vnc_display_add_client(DisplayState *ds, int csock, int skipauth)
|
||||||
{
|
{
|
||||||
VncDisplay *vs = ds ? (VncDisplay *)ds->opaque : vnc_display;
|
VncDisplay *vs = vnc_display;
|
||||||
|
|
||||||
vnc_connect(vs, csock, skipauth, 0);
|
vnc_connect(vs, csock, skipauth, 0);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user