#include "qemu/osdep.h"
#include "qapi/error.h"
#include "qapi/qapi-commands-control.h"
+#include "qapi/qapi-commands-machine.h"
#include "qapi/qapi-commands-misc.h"
#include "qemu/cutils.h"
#include <math.h>
#include "trace.h"
+#include "qemu/cutils.h"
#include "ui/input.h"
#include "sysemu/runstate.h"
#include "sysemu/sysemu.h"
DisplayOptions *opts;
};
-typedef struct VCChardev {
+struct VCChardev {
Chardev parent;
VirtualConsole *console;
bool echo;
-} 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)
bool gtk_use_gl_area;
int ww, wh;
ww = gdk_window_get_width(gtk_widget_get_window(area));
wh = gdk_window_get_height(gtk_widget_get_window(area));
-#if defined(CONFIG_GTK_GL)
+#if defined(CONFIG_OPENGL)
if (vc->gfx.gls && gtk_use_gl_area) {
gtk_gl_area_queue_render(GTK_GL_AREA(vc->gfx.drawing_area));
return;
}
vc->gfx.ds = surface;
- if (!surface) {
- return;
- }
-
if (surface->format == PIXMAN_x8r8g8b8) {
/*
* PIXMAN_x8r8g8b8 == CAIRO_FORMAT_RGB24
#if defined(CONFIG_OPENGL)
-/** DisplayState Callbacks (opengl version) **/
+static bool gd_has_dmabuf(DisplayChangeListener *dcl)
+{
+ VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
+
+ if (gtk_use_gl_area && !gtk_widget_get_realized(vc->gfx.drawing_area)) {
+ /* FIXME: Assume it will work, actual check done after realize */
+ /* fixing this would require delaying listener registration */
+ return true;
+ }
-#if defined(CONFIG_GTK_GL)
+ return vc->gfx.has_dmabuf;
+}
+
+/** DisplayState Callbacks (opengl version) **/
static const DisplayChangeListenerOps dcl_gl_area_ops = {
.dpy_name = "gtk-egl",
.dpy_gl_ctx_create = gd_gl_area_create_context,
.dpy_gl_ctx_destroy = gd_gl_area_destroy_context,
.dpy_gl_ctx_make_current = gd_gl_area_make_current,
- .dpy_gl_ctx_get_current = gd_gl_area_get_current_context,
.dpy_gl_scanout_texture = gd_gl_area_scanout_texture,
+ .dpy_gl_scanout_disable = gd_gl_area_scanout_disable,
.dpy_gl_update = gd_gl_area_scanout_flush,
+ .dpy_gl_scanout_dmabuf = gd_gl_area_scanout_dmabuf,
+ .dpy_has_dmabuf = gd_has_dmabuf,
};
-#endif /* CONFIG_GTK_GL */
+#ifdef CONFIG_X11
static const DisplayChangeListenerOps dcl_egl_ops = {
.dpy_name = "gtk-egl",
.dpy_gl_ctx_create = gd_egl_create_context,
.dpy_gl_ctx_destroy = qemu_egl_destroy_context,
.dpy_gl_ctx_make_current = gd_egl_make_current,
- .dpy_gl_ctx_get_current = qemu_egl_get_current_context,
.dpy_gl_scanout_disable = gd_egl_scanout_disable,
.dpy_gl_scanout_texture = gd_egl_scanout_texture,
.dpy_gl_scanout_dmabuf = gd_egl_scanout_dmabuf,
.dpy_gl_cursor_position = gd_egl_cursor_position,
.dpy_gl_release_dmabuf = gd_egl_release_dmabuf,
.dpy_gl_update = gd_egl_scanout_flush,
+ .dpy_has_dmabuf = gd_has_dmabuf,
};
+#endif
+
#endif /* CONFIG_OPENGL */
/** QEMU Events **/
dpy_set_ui_info(vc->gfx.dcl.con, &info);
}
-#if defined(CONFIG_GTK_GL)
+#if defined(CONFIG_OPENGL)
static gboolean gd_render_event(GtkGLArea *area, GdkGLContext *context,
void *opaque)
#endif
+/*
+ * If available, return the update interval of the monitor in ms,
+ * else return 0 (the default update interval).
+ */
+int gd_monitor_update_interval(GtkWidget *widget)
+{
+#ifdef GDK_VERSION_3_22
+ GdkWindow *win = gtk_widget_get_window(widget);
+
+ if (win) {
+ GdkDisplay *dpy = gtk_widget_get_display(widget);
+ GdkMonitor *monitor = gdk_display_get_monitor_at_window(dpy, win);
+ int refresh_rate = gdk_monitor_get_refresh_rate(monitor); /* [mHz] */
+
+ if (refresh_rate) {
+ /* T = 1 / f = 1 [s*Hz] / f = 1000*1000 [ms*mHz] / f */
+ return MIN(1000 * 1000 / refresh_rate,
+ GUI_REFRESH_INTERVAL_DEFAULT);
+ }
+ }
+#endif
+ return 0;
+}
+
static gboolean gd_draw_event(GtkWidget *widget, cairo_t *cr, void *opaque)
{
VirtualConsole *vc = opaque;
/* invoke render callback please */
return FALSE;
} else {
+#ifdef CONFIG_X11
gd_egl_draw(vc);
return TRUE;
+#else
+ abort();
+#endif
}
}
#endif
return FALSE;
}
+ vc->gfx.dcl.update_interval =
+ gd_monitor_update_interval(vc->window ? vc->window : s->window);
+
fbw = surface_width(vc->gfx.ds);
fbh = surface_height(vc->gfx.ds);
}
}
- qemu_chr_be_write(vc->vte.chr, (uint8_t *)text, (unsigned int)size);
+ int remaining = size;
+ uint8_t* p = (uint8_t *)text;
+ while (remaining > 0) {
+ int can_write = qemu_chr_be_can_write(vc->vte.chr);
+ int written = MIN(remaining, can_write);
+ qemu_chr_be_write(vc->vte.chr, p, written);
+
+ remaining -= written;
+ p += written;
+ }
return TRUE;
}
{
g_signal_connect(vc->gfx.drawing_area, "draw",
G_CALLBACK(gd_draw_event), vc);
-#if defined(CONFIG_GTK_GL)
+#if defined(CONFIG_OPENGL)
if (gtk_use_gl_area) {
/* wire up GtkGlArea events */
g_signal_connect(vc->gfx.drawing_area, "render",
return machine_menu;
}
-/*
- * If available, return the refresh rate of the display in milli-Hertz,
- * else return 0.
- */
-static int gd_refresh_rate_millihz(GtkWidget *window)
+#if defined(CONFIG_OPENGL)
+static void gl_area_realize(GtkGLArea *area, VirtualConsole *vc)
{
-#ifdef GDK_VERSION_3_22
- GdkWindow *win = gtk_widget_get_window(window);
-
- if (win) {
- GdkDisplay *dpy = gtk_widget_get_display(window);
- GdkMonitor *monitor = gdk_display_get_monitor_at_window(dpy, win);
-
- return gdk_monitor_get_refresh_rate(monitor);
+ gtk_gl_area_make_current(area);
+ qemu_egl_display = eglGetCurrentDisplay();
+ vc->gfx.has_dmabuf = qemu_egl_has_dmabuf();
+ if (!vc->gfx.has_dmabuf) {
+ error_report("GtkGLArea console lacks DMABUF support.");
}
-#endif
- return 0;
}
+#endif
static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc,
QemuConsole *con, int idx,
GSList *group, GtkWidget *view_menu)
{
bool zoom_to_fit = false;
- int refresh_rate_millihz;
vc->label = qemu_console_get_label(con);
vc->s = s;
#if defined(CONFIG_OPENGL)
if (display_opengl) {
-#if defined(CONFIG_GTK_GL)
if (gtk_use_gl_area) {
vc->gfx.drawing_area = gtk_gl_area_new();
+ g_signal_connect(vc->gfx.drawing_area, "realize",
+ G_CALLBACK(gl_area_realize), vc);
vc->gfx.dcl.ops = &dcl_gl_area_ops;
- } else
-#endif /* CONFIG_GTK_GL */
- {
+ } else {
+#ifdef CONFIG_X11
vc->gfx.drawing_area = gtk_drawing_area_new();
/*
* gtk_widget_set_double_buffered() was deprecated in 3.14.
* proper replacement (native opengl support) is only
* available in 3.16+. Silence the warning if possible.
*/
-#ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-#endif
gtk_widget_set_double_buffered(vc->gfx.drawing_area, FALSE);
-#ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE
#pragma GCC diagnostic pop
-#endif
vc->gfx.dcl.ops = &dcl_egl_ops;
+ vc->gfx.has_dmabuf = qemu_egl_has_dmabuf();
+#else
+ abort();
+#endif
}
} else
#endif
vc->gfx.kbd = qkbd_state_init(con);
vc->gfx.dcl.con = con;
- refresh_rate_millihz = gd_refresh_rate_millihz(vc->window ?
- vc->window : s->window);
- if (refresh_rate_millihz) {
- vc->gfx.dcl.update_interval = MILLISEC_PER_SEC / refresh_rate_millihz;
- }
-
register_displaychangelistener(&vc->gfx.dcl);
gd_connect_vc_gfx_signals(vc);
GtkDisplayState *s = g_malloc0(sizeof(*s));
GdkDisplay *window_display;
GtkIconTheme *theme;
+ char *dir;
if (!gtkinit) {
fprintf(stderr, "gtk initialization failed\n");
s->opts = opts;
theme = gtk_icon_theme_get_default();
- gtk_icon_theme_prepend_search_path(theme, CONFIG_QEMU_ICONDIR);
+ dir = get_relocated_path(CONFIG_QEMU_ICONDIR);
+ gtk_icon_theme_prepend_search_path(theme, dir);
+ g_free(dir);
g_set_prgname("qemu");
s->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
* sure that we don't accidentally break implicit assumptions. */
setlocale(LC_MESSAGES, "");
setlocale(LC_CTYPE, "C.UTF-8");
- bindtextdomain("qemu", CONFIG_QEMU_LOCALEDIR);
+ dir = get_relocated_path(CONFIG_QEMU_LOCALEDIR);
+ bindtextdomain("qemu", dir);
+ g_free(dir);
bind_textdomain_codeset("qemu", "UTF-8");
textdomain("qemu");
assert(opts->type == DISPLAY_TYPE_GTK);
if (opts->has_gl && opts->gl != DISPLAYGL_MODE_OFF) {
#if defined(CONFIG_OPENGL)
-#if defined(CONFIG_GTK_GL) && defined(GDK_WINDOWING_WAYLAND)
+#if defined(GDK_WINDOWING_WAYLAND)
if (GDK_IS_WAYLAND_DISPLAY(gdk_display_get_default())) {
gtk_use_gl_area = true;
gtk_gl_area_init();
} else
#endif
{
+#ifdef CONFIG_X11
DisplayGLMode mode = opts->has_gl ? opts->gl : DISPLAYGL_MODE_ON;
gtk_egl_init(mode);
+#endif
}
#endif
}