#include "trace.h"
#include "exec/memory.h"
#include "io/channel-file.h"
+#include "qom/object.h"
#define DEFAULT_BACKSCROLL 512
#define CONSOLE_CURSOR_PERIOD 500
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);
}
}
}
}
-typedef struct VCChardev {
+struct VCChardev {
Chardev parent;
QemuConsole *console;
-} VCChardev;
+};
+typedef struct VCChardev VCChardev;
#define TYPE_CHARDEV_VC "chardev-vc"
-#define VC_CHARDEV(obj) OBJECT_CHECK(VCChardev, (obj), TYPE_CHARDEV_VC)
+DECLARE_INSTANCE_CHECKER(VCChardev, VC_CHARDEV,
+ TYPE_CHARDEV_VC)
static int vc_chr_write(Chardev *chr, const uint8_t *buf, int len)
{
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 con->gl != NULL;
}
-bool console_has_gl_dmabuf(QemuConsole *con)
+static bool displaychangelistener_has_dmabuf(DisplayChangeListener *dcl)
{
- return con->gl != NULL && con->gl->ops->dpy_gl_scanout_dmabuf != NULL;
+ 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)
+{
+ 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);
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;
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,
}
graphic_console_set_hwops(s, hw_ops, opaque);
if (dev) {
- object_property_set_link(OBJECT(s), OBJECT(dev), "device",
+ object_property_set_link(OBJECT(s), "device", OBJECT(dev),
&error_abort);
}
}
trace_console_gfx_close(con->index);
- object_property_set_link(OBJECT(con), NULL, "device", &error_abort);
+ object_property_set_link(OBJECT(con), "device", NULL, &error_abort);
graphic_console_set_hwops(con, &unused_ops, NULL);
if (con->gl) {
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) {
text_console_resize(s);
if (chr->label) {
- char msg[128];
- int len;
+ char *msg;
s->t_attrib.bgcol = QEMU_COLOR_BLUE;
- len = snprintf(msg, sizeof(msg), "%s console\r\n", chr->label);
- vc_chr_write(chr, (uint8_t *)msg, len);
+ msg = g_strdup_printf("%s console\r\n", chr->label);
+ vc_chr_write(chr, (uint8_t *)msg, strlen(msg));
+ g_free(msg);
s->t_attrib = s->t_attrib_default;
}