QEMUFIFO out_fifo;
uint8_t out_fifo_buf[16];
QEMUTimer *kbd_timer;
+ CoQueue dump_queue;
QTAILQ_ENTRY(QemuConsole) next;
};
static DisplayState *get_alloc_displaystate(void);
static void text_console_update_cursor_timer(void);
static void text_console_update_cursor(void *opaque);
-static bool ppm_save(int fd, DisplaySurface *ds, Error **errp);
static void gui_update(void *opaque)
{
timer_mod(ds->gui_timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
}
if (!need_timer && ds->gui_timer != NULL) {
- timer_del(ds->gui_timer);
timer_free(ds->gui_timer);
ds->gui_timer = NULL;
}
void graphic_hw_update_done(QemuConsole *con)
{
+ if (con) {
+ qemu_co_queue_restart_all(&con->dump_queue);
+ }
}
void graphic_hw_update(QemuConsole *con)
{
bool async = false;
+ con = con ? con : active_console;
if (!con) {
- con = active_console;
+ return;
}
- if (con && con->hw_ops->gfx_update) {
+ if (con->hw_ops->gfx_update) {
con->hw_ops->gfx_update(con->hw);
async = con->hw_ops->gfx_update_async;
}
}
}
+void graphic_hw_gl_flushed(QemuConsole *con)
+{
+ assert(con != NULL);
+
+ if (con->hw_ops->gl_flushed) {
+ con->hw_ops->gl_flushed(con->hw);
+ }
+}
+
int qemu_console_get_window_id(QemuConsole *con)
{
return con->window_id;
}
}
-static bool ppm_save(int fd, DisplaySurface *ds, Error **errp)
+static bool ppm_save(int fd, pixman_image_t *image, Error **errp)
{
- int width = pixman_image_get_width(ds->image);
- int height = pixman_image_get_height(ds->image);
+ int width = pixman_image_get_width(image);
+ int height = pixman_image_get_height(image);
g_autoptr(Object) ioc = OBJECT(qio_channel_file_new_fd(fd));
g_autofree char *header = NULL;
g_autoptr(pixman_image_t) linebuf = NULL;
int y;
- trace_ppm_save(fd, ds);
+ trace_ppm_save(fd, image);
header = g_strdup_printf("P6\n%d %d\n%d\n", width, height, 255);
if (qio_channel_write_all(QIO_CHANNEL(ioc),
linebuf = qemu_pixman_linebuf_create(PIXMAN_BE_r8g8b8, width);
for (y = 0; y < height; y++) {
- qemu_pixman_linebuf_fill(linebuf, ds->image, width, 0, y);
+ qemu_pixman_linebuf_fill(linebuf, image, width, 0, y);
if (qio_channel_write_all(QIO_CHANNEL(ioc),
(char *)pixman_image_get_data(linebuf),
pixman_image_get_stride(linebuf), errp) < 0) {
return true;
}
-void qmp_screendump(const char *filename, bool has_device, const char *device,
- bool has_head, int64_t head, Error **errp)
+static void graphic_hw_update_bh(void *con)
+{
+ graphic_hw_update(con);
+}
+
+/* Safety: coroutine-only, concurrent-coroutine safe, main thread only */
+void coroutine_fn
+qmp_screendump(const char *filename, bool has_device, const char *device,
+ bool has_head, int64_t head, Error **errp)
{
+ g_autoptr(pixman_image_t) image = NULL;
QemuConsole *con;
DisplaySurface *surface;
int fd;
}
}
- graphic_hw_update(con);
+ if (qemu_co_queue_empty(&con->dump_queue)) {
+ /* Defer the update, it will restart the pending coroutines */
+ aio_bh_schedule_oneshot(qemu_get_aio_context(),
+ graphic_hw_update_bh, con);
+ }
+ qemu_co_queue_wait(&con->dump_queue, NULL);
+
+ /*
+ * All pending coroutines are woken up, while the BQL is held. No
+ * further graphic update are possible until it is released. Take
+ * an image ref before that.
+ */
surface = qemu_console_surface(con);
if (!surface) {
error_setg(errp, "no surface");
return;
}
+ image = pixman_image_ref(surface->image);
- fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666);
+ fd = qemu_open_old(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666);
if (fd == -1) {
error_setg(errp, "failed to open file '%s': %s", filename,
strerror(errno));
return;
}
- if (!ppm_save(fd, surface, errp)) {
+ /*
+ * The image content could potentially be updated as the coroutine
+ * yields and releases the BQL. It could produce corrupted dump, but
+ * it should be otherwise safe.
+ */
+ if (!ppm_save(fd, image, errp)) {
qemu_unlink(filename);
}
}
obj = object_new(TYPE_QEMU_CONSOLE);
s = QEMU_CONSOLE(obj);
+ qemu_co_queue_init(&s->dump_queue);
s->head = head;
object_property_add_link(obj, "device", TYPE_DEVICE,
(Object **)&s->device,
}
s->ds = ds;
s->console_type = console_type;
+ s->window_id = -1;
if (QTAILQ_EMPTY(&consoles)) {
s->index = 0;
QTAILQ_INSERT_TAIL(&consoles, s, next);
- } else if (console_type != GRAPHIC_CONSOLE || qdev_hotplug) {
+ } else if (console_type != GRAPHIC_CONSOLE || phase_check(PHASE_MACHINE_READY)) {
QemuConsole *last = QTAILQ_LAST(&consoles);
s->index = last->index + 1;
QTAILQ_INSERT_TAIL(&consoles, s, next);
return s;
}
-static void qemu_alloc_display(DisplaySurface *surface, int width, int height)
+DisplaySurface *qemu_create_displaysurface(int width, int height)
{
- qemu_pixman_image_unref(surface->image);
- surface->image = NULL;
+ DisplaySurface *surface = g_new0(DisplaySurface, 1);
+ trace_displaysurface_create(surface, width, height);
surface->format = PIXMAN_x8r8g8b8;
surface->image = pixman_image_create_bits(surface->format,
width, height,
NULL, width * 4);
assert(surface->image != NULL);
-
surface->flags = QEMU_ALLOCATED_FLAG;
-}
-DisplaySurface *qemu_create_displaysurface(int width, int height)
-{
- DisplaySurface *surface = g_new0(DisplaySurface, 1);
-
- trace_displaysurface_create(surface, width, height);
- qemu_alloc_display(surface, width, height);
return surface;
}
return surface;
}
-DisplaySurface *qemu_create_message_surface(int w, int h,
- const char *msg)
+DisplaySurface *qemu_create_placeholder_surface(int w, int h,
+ const char *msg)
{
DisplaySurface *surface = qemu_create_displaysurface(w, h);
pixman_color_t bg = color_table_rgb[0][QEMU_COLOR_BLACK];
x+i, y, FONT_WIDTH, FONT_HEIGHT);
qemu_pixman_image_unref(glyph);
}
+ surface->flags |= QEMU_PLACEHOLDER_FLAG;
return surface;
}
return con->gl != NULL;
}
-bool console_has_gl_dmabuf(QemuConsole *con)
+static bool displaychangelistener_has_dmabuf(DisplayChangeListener *dcl)
+{
+ if (dcl->ops->dpy_has_dmabuf) {
+ return dcl->ops->dpy_has_dmabuf(dcl);
+ }
+
+ if (dcl->ops->dpy_gl_scanout_dmabuf) {
+ return true;
+ }
+
+ return false;
+}
+
+static bool dpy_compatible_with(QemuConsole *con,
+ DisplayChangeListener *dcl, Error **errp)
{
- return con->gl != NULL && con->gl->ops->dpy_gl_scanout_dmabuf != NULL;
+ ERRP_GUARD();
+ int flags;
+
+ flags = con->hw_ops->get_flags ? con->hw_ops->get_flags(con->hw) : 0;
+
+ if (flags & GRAPHIC_FLAGS_GL &&
+ !console_has_gl(con)) {
+ error_setg(errp, "The console requires a GL context.");
+ return false;
+
+ }
+
+ if (flags & GRAPHIC_FLAGS_DMABUF &&
+ !displaychangelistener_has_dmabuf(dcl)) {
+ error_setg(errp, "The console requires display DMABUF support.");
+ return false;
+ }
+
+ return true;
}
void register_displaychangelistener(DisplayChangeListener *dcl)
"This VM has no graphic display device.";
static DisplaySurface *dummy;
QemuConsole *con;
+ Error *err = NULL;
assert(!dcl->ds);
dcl->con->gl = dcl;
}
+ if (dcl->con && !dpy_compatible_with(dcl->con, dcl, &err)) {
+ error_report_err(err);
+ exit(1);
+ }
+
trace_displaychangelistener_register(dcl, dcl->ops->dpy_name);
dcl->ds = get_alloc_displaystate();
QLIST_INSERT_HEAD(&dcl->ds->listeners, dcl, next);
dcl->ops->dpy_gfx_switch(dcl, con->surface);
} else {
if (!dummy) {
- dummy = qemu_create_message_surface(640, 480, nodev);
+ dummy = qemu_create_placeholder_surface(640, 480, nodev);
}
dcl->ops->dpy_gfx_switch(dcl, dummy);
}
bool dpy_ui_info_supported(QemuConsole *con)
{
+ if (con == NULL) {
+ con = active_console;
+ }
+
return con->hw_ops->ui_info != NULL;
}
+const QemuUIInfo *dpy_get_ui_info(const QemuConsole *con)
+{
+ if (con == NULL) {
+ con = active_console;
+ }
+
+ return &con->ui_info;
+}
+
int dpy_set_ui_info(QemuConsole *con, QemuUIInfo *info)
{
- assert(con != NULL);
+ if (con == NULL) {
+ con = active_console;
+ }
if (!dpy_ui_info_supported(con)) {
return -1;
void dpy_gfx_replace_surface(QemuConsole *con,
DisplaySurface *surface)
{
+ static const char placeholder_msg[] = "Display output is not active.";
DisplayState *s = con->ds;
DisplaySurface *old_surface = con->surface;
DisplayChangeListener *dcl;
+ int width;
+ int height;
+
+ if (!surface) {
+ if (old_surface) {
+ width = surface_width(old_surface);
+ height = surface_height(old_surface);
+ } else {
+ width = 640;
+ height = 480;
+ }
+
+ surface = qemu_create_placeholder_surface(width, height, placeholder_msg);
+ }
- assert(old_surface != surface || surface == NULL);
+ assert(old_surface != surface);
con->surface = surface;
QLIST_FOREACH(dcl, &s->listeners, next) {
return false;
}
} else {
- /* default is to whitelist native 32 bpp only */
+ /* default is to allow native 32 bpp only */
if (format != qemu_default_pixman_format(32, true)) {
return false;
}
return con->gl->ops->dpy_gl_ctx_make_current(con->gl, ctx);
}
-QEMUGLContext dpy_gl_ctx_get_current(QemuConsole *con)
-{
- assert(con->gl);
- return con->gl->ops->dpy_gl_ctx_get_current(con->gl);
-}
-
void dpy_gl_scanout_disable(QemuConsole *con)
{
assert(con->gl);
- if (con->gl->ops->dpy_gl_scanout_disable) {
- con->gl->ops->dpy_gl_scanout_disable(con->gl);
- } else {
- con->gl->ops->dpy_gl_scanout_texture(con->gl, 0, false, 0, 0,
- 0, 0, 0, 0);
- }
+ con->gl->ops->dpy_gl_scanout_disable(con->gl);
}
void dpy_gl_scanout_texture(QemuConsole *con,
&error_abort);
}
- surface = qemu_create_message_surface(width, height, noinit);
+ surface = qemu_create_placeholder_surface(width, height, noinit);
dpy_gfx_replace_surface(s, surface);
return s;
}
if (con->gl) {
dpy_gl_scanout_disable(con);
}
- surface = qemu_create_message_surface(width, height, unplugged);
+ surface = qemu_create_placeholder_surface(width, height, unplugged);
dpy_gfx_replace_surface(con, surface);
}
return con ? con->head : -1;
}
-QemuUIInfo *qemu_console_get_ui_info(QemuConsole *con)
-{
- assert(con != NULL);
- return &con->ui_info;
-}
-
int qemu_console_get_width(QemuConsole *con, int fallback)
{
if (con == NULL) {