Commit 7c20b4a3 authored by Gerd Hoffmann's avatar Gerd Hoffmann
Browse files

console: fix displaychangelisteners interface



Split callbacks into separate Ops struct.  Pass DisplayChangeListener
pointer as first argument to all callbacks.  Uninline a bunch of
display functions and move them from console.h to console.c

Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
parent 225dc991
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -1866,21 +1866,25 @@ static void qxl_vm_change_state_handler(void *opaque, int running,

/* display change listener */

static void display_update(struct DisplayState *ds, int x, int y, int w, int h)
static void display_update(DisplayChangeListener *dcl,
                           struct DisplayState *ds,
                           int x, int y, int w, int h)
{
    if (qxl0->mode == QXL_MODE_VGA) {
        qemu_spice_display_update(&qxl0->ssd, x, y, w, h);
    }
}

static void display_resize(struct DisplayState *ds)
static void display_resize(DisplayChangeListener *dcl,
                           struct DisplayState *ds)
{
    if (qxl0->mode == QXL_MODE_VGA) {
        qemu_spice_display_resize(&qxl0->ssd);
    }
}

static void display_refresh(struct DisplayState *ds)
static void display_refresh(DisplayChangeListener *dcl,
                            struct DisplayState *ds)
{
    if (qxl0->mode == QXL_MODE_VGA) {
        qemu_spice_display_refresh(&qxl0->ssd);
@@ -1891,7 +1895,8 @@ static void display_refresh(struct DisplayState *ds)
    }
}

static DisplayChangeListener display_listener = {
static DisplayChangeListenerOps display_listener_ops = {
    .dpy_name        = "spice/qxl",
    .dpy_gfx_update  = display_update,
    .dpy_gfx_resize  = display_resize,
    .dpy_refresh     = display_refresh,
@@ -2076,7 +2081,8 @@ static int qxl_init_primary(PCIDevice *dev)
        return rc;
    }

    register_displaychangelistener(vga->ds, &display_listener);
    qxl->ssd.dcl.ops = &display_listener_ops;
    register_displaychangelistener(vga->ds, &qxl->ssd.dcl);
    return rc;
}

+53 −154
Original line number Diff line number Diff line
@@ -147,24 +147,46 @@ void cursor_set_mono(QEMUCursor *c,
void cursor_get_mono_image(QEMUCursor *c, int foreground, uint8_t *mask);
void cursor_get_mono_mask(QEMUCursor *c, int transparent, uint8_t *mask);

struct DisplayChangeListener {
    int idle;
    uint64_t gui_timer_interval;

    void (*dpy_refresh)(struct DisplayState *s);

    void (*dpy_gfx_update)(struct DisplayState *s, int x, int y, int w, int h);
    void (*dpy_gfx_resize)(struct DisplayState *s);
    void (*dpy_gfx_setdata)(struct DisplayState *s);
    void (*dpy_gfx_copy)(struct DisplayState *s, int src_x, int src_y,
typedef struct DisplayChangeListenerOps {
    const char *dpy_name;

    void (*dpy_refresh)(DisplayChangeListener *dcl,
                        struct DisplayState *s);

    void (*dpy_gfx_update)(DisplayChangeListener *dcl,
                           struct DisplayState *s,
                           int x, int y, int w, int h);
    void (*dpy_gfx_resize)(DisplayChangeListener *dcl,
                           struct DisplayState *s);
    void (*dpy_gfx_setdata)(DisplayChangeListener *dcl,
                            struct DisplayState *s);
    void (*dpy_gfx_copy)(DisplayChangeListener *dcl,
                         struct DisplayState *s, int src_x, int src_y,
                         int dst_x, int dst_y, int w, int h);

    void (*dpy_text_cursor)(struct DisplayState *s, int x, int y);
    void (*dpy_text_resize)(struct DisplayState *s, int w, int h);
    void (*dpy_text_update)(struct DisplayState *s, int x, int y, int w, int h);
    void (*dpy_text_cursor)(DisplayChangeListener *dcl,
                            struct DisplayState *s,
                            int x, int y);
    void (*dpy_text_resize)(DisplayChangeListener *dcl,
                            struct DisplayState *s,
                            int w, int h);
    void (*dpy_text_update)(DisplayChangeListener *dcl,
                            struct DisplayState *s,
                            int x, int y, int w, int h);

    void (*dpy_mouse_set)(DisplayChangeListener *dcl,
                          struct DisplayState *s,
                          int x, int y, int on);
    void (*dpy_cursor_define)(DisplayChangeListener *dcl,
                              struct DisplayState *s,
                              QEMUCursor *cursor);
} DisplayChangeListenerOps;

    void (*dpy_mouse_set)(struct DisplayState *s, int x, int y, int on);
    void (*dpy_cursor_define)(struct DisplayState *s, QEMUCursor *cursor);
struct DisplayChangeListener {
    int idle;
    uint64_t gui_timer_interval;
    const DisplayChangeListenerOps *ops;
    DisplayState *ds;

    QLIST_ENTRY(DisplayChangeListener) next;
};
@@ -210,145 +232,22 @@ static inline int is_buffer_shared(DisplaySurface *surface)

void gui_setup_refresh(DisplayState *ds);

static inline void register_displaychangelistener(DisplayState *ds, DisplayChangeListener *dcl)
{
    QLIST_INSERT_HEAD(&ds->listeners, dcl, next);
    gui_setup_refresh(ds);
    if (dcl->dpy_gfx_resize) {
        dcl->dpy_gfx_resize(ds);
    }
}

static inline void unregister_displaychangelistener(DisplayState *ds,
                                                    DisplayChangeListener *dcl)
{
    QLIST_REMOVE(dcl, next);
    gui_setup_refresh(ds);
}
void register_displaychangelistener(DisplayState *ds,
                                    DisplayChangeListener *dcl);
void unregister_displaychangelistener(DisplayChangeListener *dcl);

static inline void dpy_gfx_update(DisplayState *s, int x, int y, int w, int h)
{
    struct DisplayChangeListener *dcl;
    int width = pixman_image_get_width(s->surface->image);
    int height = pixman_image_get_height(s->surface->image);

    x = MAX(x, 0);
    y = MAX(y, 0);
    x = MIN(x, width);
    y = MIN(y, height);
    w = MIN(w, width - x);
    h = MIN(h, height - y);

    QLIST_FOREACH(dcl, &s->listeners, next) {
        if (dcl->dpy_gfx_update) {
            dcl->dpy_gfx_update(s, x, y, w, h);
        }
    }
}

static inline void dpy_gfx_resize(DisplayState *s)
{
    struct DisplayChangeListener *dcl;
    QLIST_FOREACH(dcl, &s->listeners, next) {
        if (dcl->dpy_gfx_resize) {
            dcl->dpy_gfx_resize(s);
        }
    }
}

static inline void dpy_gfx_setdata(DisplayState *s)
{
    struct DisplayChangeListener *dcl;
    QLIST_FOREACH(dcl, &s->listeners, next) {
        if (dcl->dpy_gfx_setdata) {
            dcl->dpy_gfx_setdata(s);
        }
    }
}

static inline void dpy_refresh(DisplayState *s)
{
    struct DisplayChangeListener *dcl;
    QLIST_FOREACH(dcl, &s->listeners, next) {
        if (dcl->dpy_refresh) {
            dcl->dpy_refresh(s);
        }
    }
}

static inline void dpy_gfx_copy(struct DisplayState *s, int src_x, int src_y,
                             int dst_x, int dst_y, int w, int h)
{
    struct DisplayChangeListener *dcl;
    QLIST_FOREACH(dcl, &s->listeners, next) {
        if (dcl->dpy_gfx_copy) {
            dcl->dpy_gfx_copy(s, src_x, src_y, dst_x, dst_y, w, h);
        } else { /* TODO */
            dcl->dpy_gfx_update(s, dst_x, dst_y, w, h);
        }
    }
}

static inline void dpy_text_cursor(struct DisplayState *s, int x, int y)
{
    struct DisplayChangeListener *dcl;
    QLIST_FOREACH(dcl, &s->listeners, next) {
        if (dcl->dpy_text_cursor) {
            dcl->dpy_text_cursor(s, x, y);
        }
    }
}

static inline void dpy_text_update(DisplayState *s, int x, int y, int w, int h)
{
    struct DisplayChangeListener *dcl;
    QLIST_FOREACH(dcl, &s->listeners, next) {
        if (dcl->dpy_text_update) {
            dcl->dpy_text_update(s, x, y, w, h);
        }
    }
}

static inline void dpy_text_resize(DisplayState *s, int w, int h)
{
    struct DisplayChangeListener *dcl;
    QLIST_FOREACH(dcl, &s->listeners, next) {
        if (dcl->dpy_text_resize) {
            dcl->dpy_text_resize(s, w, h);
        }
    }
}

static inline void dpy_mouse_set(struct DisplayState *s, int x, int y, int on)
{
    struct DisplayChangeListener *dcl;
    QLIST_FOREACH(dcl, &s->listeners, next) {
        if (dcl->dpy_mouse_set) {
            dcl->dpy_mouse_set(s, x, y, on);
        }
    }
}

static inline void dpy_cursor_define(struct DisplayState *s, QEMUCursor *cursor)
{
    struct DisplayChangeListener *dcl;
    QLIST_FOREACH(dcl, &s->listeners, next) {
        if (dcl->dpy_cursor_define) {
            dcl->dpy_cursor_define(s, cursor);
        }
    }
}

static inline bool dpy_cursor_define_supported(struct DisplayState *s)
{
    struct DisplayChangeListener *dcl;
    QLIST_FOREACH(dcl, &s->listeners, next) {
        if (dcl->dpy_cursor_define) {
            return true;
        }
    }
    return false;
}
void dpy_gfx_update(DisplayState *s, int x, int y, int w, int h);
void dpy_gfx_resize(DisplayState *s);
void dpy_gfx_setdata(DisplayState *s);
void dpy_refresh(DisplayState *s);
void dpy_gfx_copy(struct DisplayState *s, int src_x, int src_y,
                  int dst_x, int dst_y, int w, int h);
void dpy_text_cursor(struct DisplayState *s, int x, int y);
void dpy_text_update(DisplayState *s, int x, int y, int w, int h);
void dpy_text_resize(DisplayState *s, int w, int h);
void dpy_mouse_set(struct DisplayState *s, int x, int y, int on);
void dpy_cursor_define(struct DisplayState *s, QEMUCursor *cursor);
bool dpy_cursor_define_supported(struct DisplayState *s);

static inline int ds_get_linesize(DisplayState *ds)
{
+1 −0
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ typedef struct SimpleSpiceUpdate SimpleSpiceUpdate;

struct SimpleSpiceDisplay {
    DisplayState *ds;
    DisplayChangeListener dcl;
    void *buf;
    int bufsize;
    QXLWorker *worker;
+2 −0
Original line number Diff line number Diff line
@@ -960,6 +960,8 @@ dma_map_wait(void *dbs) "dbs=%p"
# console.h
displaysurface_free(void *display_state, void *display_surface) "state=%p surface=%p"
displaysurface_resize(void *display_state, void *display_surface, int width, int height) "state=%p surface=%p %dx%d"
displaychangelistener_register(void *dcl, const char *name) "%p [ %s ]"
displaychangelistener_unregister(void *dcl, const char *name) "%p [ %s ]"

# vga.c
ppm_save(const char *filename, void *display_surface) "%s surface=%p"
+17 −9
Original line number Diff line number Diff line
@@ -969,7 +969,9 @@ int main (int argc, const char * argv[]) {


#pragma mark qemu
static void cocoa_update(DisplayState *ds, int x, int y, int w, int h)
static void cocoa_update(DisplayChangeListener *dcl,
                         DisplayState *ds,
                         int x, int y, int w, int h)
{
    COCOA_DEBUG("qemu_cocoa: cocoa_update\n");

@@ -986,14 +988,16 @@ static void cocoa_update(DisplayState *ds, int x, int y, int w, int h)
    [cocoaView setNeedsDisplayInRect:rect];
}

static void cocoa_resize(DisplayState *ds)
static void cocoa_resize(DisplayChangeListener *dcl,
                         DisplayState *ds)
{
    COCOA_DEBUG("qemu_cocoa: cocoa_resize\n");

    [cocoaView resizeContentToWidth:(int)(ds_get_width(ds)) height:(int)(ds_get_height(ds)) displayState:ds];
}

static void cocoa_refresh(DisplayState *ds)
static void cocoa_refresh(DisplayChangeListener *dcl,
                          DisplayState *ds)
{
    COCOA_DEBUG("qemu_cocoa: cocoa_refresh\n");

@@ -1030,6 +1034,14 @@ static void cocoa_cleanup(void)
    g_free(dcl);
}

static const DisplayChangeListenerOps dcl_ops = {
    .dpy_name          = "cocoa",
    .dpy_gfx_update = cocoa_update;
    .dpy_gfx_resize = cocoa_resize;
    .dpy_gfx_setdata = cocoa_setdata;
    .dpy_refresh = cocoa_refresh;
};

void cocoa_display_init(DisplayState *ds, int full_screen)
{
    COCOA_DEBUG("qemu_cocoa: cocoa_display_init\n");
@@ -1037,11 +1049,7 @@ void cocoa_display_init(DisplayState *ds, int full_screen)
    dcl = g_malloc0(sizeof(DisplayChangeListener));

    // register vga output callbacks
    dcl->dpy_gfx_update = cocoa_update;
    dcl->dpy_gfx_resize = cocoa_resize;
    dcl->dpy_refresh = cocoa_refresh;
    dcl->dpy_gfx_setdata = cocoa_setdata;

    dcl->ops = &dcl_ops;
    register_displaychangelistener(ds, dcl);

    // register cleanup function
Loading