bellard | e7f0ad5 | 2004-07-14 17:28:59 +0000 | [diff] [blame] | 1 | /* |
| 2 | * QEMU graphical console |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3 | * |
bellard | e7f0ad5 | 2004-07-14 17:28:59 +0000 | [diff] [blame] | 4 | * Copyright (c) 2004 Fabrice Bellard |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 5 | * |
bellard | e7f0ad5 | 2004-07-14 17:28:59 +0000 | [diff] [blame] | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to deal |
| 8 | * in the Software without restriction, including without limitation the rights |
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | * copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | * THE SOFTWARE. |
| 23 | */ |
Markus Armbruster | e688df6 | 2018-02-01 12:18:31 +0100 | [diff] [blame] | 24 | |
Peter Maydell | e16f4c8 | 2016-01-29 17:49:51 +0000 | [diff] [blame] | 25 | #include "qemu/osdep.h" |
Paolo Bonzini | 28ecbae | 2012-11-28 12:06:30 +0100 | [diff] [blame] | 26 | #include "ui/console.h" |
Gerd Hoffmann | aa2beaa | 2013-04-17 10:21:27 +0200 | [diff] [blame] | 27 | #include "hw/qdev-core.h" |
Markus Armbruster | e688df6 | 2018-02-01 12:18:31 +0100 | [diff] [blame] | 28 | #include "qapi/error.h" |
Markus Armbruster | 9af2398 | 2018-02-11 10:36:01 +0100 | [diff] [blame] | 29 | #include "qapi/qapi-commands-ui.h" |
Marc-André Lureau | 098d57e | 2023-08-30 13:37:52 +0400 | [diff] [blame] | 30 | #include "qapi/visitor.h" |
Markus Armbruster | 68ba85c | 2022-12-21 14:14:34 +0100 | [diff] [blame] | 31 | #include "qemu/coroutine.h" |
Marc-André Lureau | 4f2c765 | 2023-08-30 13:37:37 +0400 | [diff] [blame] | 32 | #include "qemu/error-report.h" |
Volker Rümelin | 014b00c | 2021-09-16 21:22:38 +0200 | [diff] [blame] | 33 | #include "qemu/main-loop.h" |
Markus Armbruster | 0b8fa32 | 2019-05-23 16:35:07 +0200 | [diff] [blame] | 34 | #include "qemu/module.h" |
Markus Armbruster | 922a01a | 2018-02-01 12:18:46 +0100 | [diff] [blame] | 35 | #include "qemu/option.h" |
Volker Rümelin | 014b00c | 2021-09-16 21:22:38 +0200 | [diff] [blame] | 36 | #include "chardev/char.h" |
Stefan Weil | ac86048 | 2013-11-10 14:20:16 +0100 | [diff] [blame] | 37 | #include "trace.h" |
Gerd Hoffmann | a77549b | 2014-06-19 08:46:08 +0200 | [diff] [blame] | 38 | #include "exec/memory.h" |
Eduardo Habkost | db1015e | 2020-09-03 16:43:22 -0400 | [diff] [blame] | 39 | #include "qom/object.h" |
bellard | e7f0ad5 | 2004-07-14 17:28:59 +0000 | [diff] [blame] | 40 | |
Marc-André Lureau | 6f11081 | 2023-08-30 13:38:23 +0400 | [diff] [blame] | 41 | #include "console-priv.h" |
bellard | e7f0ad5 | 2004-07-14 17:28:59 +0000 | [diff] [blame] | 42 | |
Marc-André Lureau | c105d60 | 2023-08-30 13:37:54 +0400 | [diff] [blame] | 43 | OBJECT_DEFINE_ABSTRACT_TYPE(QemuConsole, qemu_console, QEMU_CONSOLE, OBJECT) |
Marc-André Lureau | e265917 | 2023-08-30 13:37:51 +0400 | [diff] [blame] | 44 | |
Marc-André Lureau | b208f74 | 2023-08-30 13:37:53 +0400 | [diff] [blame] | 45 | typedef struct QemuGraphicConsole { |
| 46 | QemuConsole parent; |
Marc-André Lureau | 58d5870 | 2023-08-30 13:38:03 +0400 | [diff] [blame] | 47 | |
| 48 | Object *device; |
| 49 | uint32_t head; |
| 50 | |
| 51 | QEMUCursor *cursor; |
| 52 | int cursor_x, cursor_y, cursor_on; |
Marc-André Lureau | b208f74 | 2023-08-30 13:37:53 +0400 | [diff] [blame] | 53 | } QemuGraphicConsole; |
| 54 | |
| 55 | typedef QemuConsoleClass QemuGraphicConsoleClass; |
| 56 | |
Marc-André Lureau | b208f74 | 2023-08-30 13:37:53 +0400 | [diff] [blame] | 57 | OBJECT_DEFINE_TYPE(QemuGraphicConsole, qemu_graphic_console, QEMU_GRAPHIC_CONSOLE, QEMU_CONSOLE) |
| 58 | |
Gerd Hoffmann | 27be558 | 2013-03-13 12:25:25 +0100 | [diff] [blame] | 59 | struct DisplayState { |
Stefan Weil | 1246b25 | 2013-12-01 08:49:47 +0100 | [diff] [blame] | 60 | QEMUTimer *gui_timer; |
Gerd Hoffmann | 0f7b286 | 2013-03-14 11:56:16 +0100 | [diff] [blame] | 61 | uint64_t last_update; |
| 62 | uint64_t update_interval; |
| 63 | bool refreshing; |
Gerd Hoffmann | 27be558 | 2013-03-13 12:25:25 +0100 | [diff] [blame] | 64 | |
| 65 | QLIST_HEAD(, DisplayChangeListener) listeners; |
| 66 | }; |
| 67 | |
Paolo Bonzini | 98b5008 | 2010-02-11 00:29:57 +0100 | [diff] [blame] | 68 | static DisplayState *display_state; |
Gerd Hoffmann | 76ffb0b | 2012-09-28 13:24:17 +0200 | [diff] [blame] | 69 | static QemuConsole *active_console; |
Paolo Bonzini | eae3eb3 | 2018-12-06 13:10:34 +0100 | [diff] [blame] | 70 | static QTAILQ_HEAD(, QemuConsole) consoles = |
Gerd Hoffmann | cd6cd8f | 2018-05-07 11:54:24 +0200 | [diff] [blame] | 71 | QTAILQ_HEAD_INITIALIZER(consoles); |
bellard | e7f0ad5 | 2004-07-14 17:28:59 +0000 | [diff] [blame] | 72 | |
Gerd Hoffmann | 0f7b286 | 2013-03-14 11:56:16 +0100 | [diff] [blame] | 73 | static void dpy_refresh(DisplayState *s); |
Gerd Hoffmann | 5209089 | 2013-04-23 15:44:31 +0200 | [diff] [blame] | 74 | static DisplayState *get_alloc_displaystate(void); |
Marc-André Lureau | ebced09 | 2021-02-20 16:23:03 +0400 | [diff] [blame] | 75 | static bool displaychangelistener_has_dmabuf(DisplayChangeListener *dcl); |
Marc-André Lureau | 4b7b661 | 2022-02-16 20:16:55 +0400 | [diff] [blame] | 76 | static bool console_compatible_with(QemuConsole *con, |
| 77 | DisplayChangeListener *dcl, Error **errp); |
Marc-André Lureau | f9411aa | 2023-08-30 13:37:57 +0400 | [diff] [blame] | 78 | static QemuConsole *qemu_graphic_console_lookup_unused(void); |
Marc-André Lureau | cfde05d | 2023-08-30 13:37:59 +0400 | [diff] [blame] | 79 | static void dpy_set_ui_info_timer(void *opaque); |
Gerd Hoffmann | 64840c6 | 2013-03-07 17:08:29 +0100 | [diff] [blame] | 80 | |
Gerd Hoffmann | 98a9ad9 | 2013-03-13 12:17:13 +0100 | [diff] [blame] | 81 | static void gui_update(void *opaque) |
| 82 | { |
Gerd Hoffmann | 0f7b286 | 2013-03-14 11:56:16 +0100 | [diff] [blame] | 83 | uint64_t interval = GUI_REFRESH_INTERVAL_IDLE; |
| 84 | uint64_t dcl_interval; |
Gerd Hoffmann | 98a9ad9 | 2013-03-13 12:17:13 +0100 | [diff] [blame] | 85 | DisplayState *ds = opaque; |
| 86 | DisplayChangeListener *dcl; |
| 87 | |
Gerd Hoffmann | 0f7b286 | 2013-03-14 11:56:16 +0100 | [diff] [blame] | 88 | ds->refreshing = true; |
Gerd Hoffmann | 98a9ad9 | 2013-03-13 12:17:13 +0100 | [diff] [blame] | 89 | dpy_refresh(ds); |
Gerd Hoffmann | 0f7b286 | 2013-03-14 11:56:16 +0100 | [diff] [blame] | 90 | ds->refreshing = false; |
Gerd Hoffmann | 98a9ad9 | 2013-03-13 12:17:13 +0100 | [diff] [blame] | 91 | |
| 92 | QLIST_FOREACH(dcl, &ds->listeners, next) { |
Gerd Hoffmann | 0f7b286 | 2013-03-14 11:56:16 +0100 | [diff] [blame] | 93 | dcl_interval = dcl->update_interval ? |
| 94 | dcl->update_interval : GUI_REFRESH_INTERVAL_DEFAULT; |
| 95 | if (interval > dcl_interval) { |
| 96 | interval = dcl_interval; |
Gerd Hoffmann | 98a9ad9 | 2013-03-13 12:17:13 +0100 | [diff] [blame] | 97 | } |
| 98 | } |
Gerd Hoffmann | 0f7b286 | 2013-03-14 11:56:16 +0100 | [diff] [blame] | 99 | if (ds->update_interval != interval) { |
| 100 | ds->update_interval = interval; |
| 101 | trace_console_refresh(interval); |
| 102 | } |
Alex Bligh | bc72ad6 | 2013-08-21 16:03:08 +0100 | [diff] [blame] | 103 | ds->last_update = qemu_clock_get_ms(QEMU_CLOCK_REALTIME); |
| 104 | timer_mod(ds->gui_timer, ds->last_update + interval); |
Gerd Hoffmann | 98a9ad9 | 2013-03-13 12:17:13 +0100 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | static void gui_setup_refresh(DisplayState *ds) |
| 108 | { |
| 109 | DisplayChangeListener *dcl; |
| 110 | bool need_timer = false; |
Gerd Hoffmann | 98a9ad9 | 2013-03-13 12:17:13 +0100 | [diff] [blame] | 111 | |
| 112 | QLIST_FOREACH(dcl, &ds->listeners, next) { |
| 113 | if (dcl->ops->dpy_refresh != NULL) { |
| 114 | need_timer = true; |
| 115 | } |
Gerd Hoffmann | 98a9ad9 | 2013-03-13 12:17:13 +0100 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | if (need_timer && ds->gui_timer == NULL) { |
Alex Bligh | bc72ad6 | 2013-08-21 16:03:08 +0100 | [diff] [blame] | 119 | ds->gui_timer = timer_new_ms(QEMU_CLOCK_REALTIME, gui_update, ds); |
| 120 | timer_mod(ds->gui_timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME)); |
Gerd Hoffmann | 98a9ad9 | 2013-03-13 12:17:13 +0100 | [diff] [blame] | 121 | } |
| 122 | if (!need_timer && ds->gui_timer != NULL) { |
Alex Bligh | bc72ad6 | 2013-08-21 16:03:08 +0100 | [diff] [blame] | 123 | timer_free(ds->gui_timer); |
Gerd Hoffmann | 98a9ad9 | 2013-03-13 12:17:13 +0100 | [diff] [blame] | 124 | ds->gui_timer = NULL; |
| 125 | } |
Gerd Hoffmann | 98a9ad9 | 2013-03-13 12:17:13 +0100 | [diff] [blame] | 126 | } |
| 127 | |
Marc-André Lureau | 4d63162 | 2015-08-24 13:20:49 +0200 | [diff] [blame] | 128 | void graphic_hw_update_done(QemuConsole *con) |
| 129 | { |
Gerd Hoffmann | 6fc5183 | 2020-11-24 13:29:36 +0100 | [diff] [blame] | 130 | if (con) { |
Paolo Bonzini | d6ee15a | 2022-04-27 15:08:29 +0200 | [diff] [blame] | 131 | qemu_co_enter_all(&con->dump_queue, NULL); |
Gerd Hoffmann | 6fc5183 | 2020-11-24 13:29:36 +0100 | [diff] [blame] | 132 | } |
Marc-André Lureau | 4d63162 | 2015-08-24 13:20:49 +0200 | [diff] [blame] | 133 | } |
| 134 | |
Gerd Hoffmann | 1dbfa00 | 2013-03-12 13:44:38 +0100 | [diff] [blame] | 135 | void graphic_hw_update(QemuConsole *con) |
pbrook | 9521989 | 2006-04-09 01:06:34 +0000 | [diff] [blame] | 136 | { |
Marc-André Lureau | 4d63162 | 2015-08-24 13:20:49 +0200 | [diff] [blame] | 137 | bool async = false; |
lichun | 1cd8b94 | 2020-11-07 01:03:39 +0800 | [diff] [blame] | 138 | con = con ? con : active_console; |
Gerd Hoffmann | 1dbfa00 | 2013-03-12 13:44:38 +0100 | [diff] [blame] | 139 | if (!con) { |
lichun | 1cd8b94 | 2020-11-07 01:03:39 +0800 | [diff] [blame] | 140 | return; |
Gerd Hoffmann | 1dbfa00 | 2013-03-12 13:44:38 +0100 | [diff] [blame] | 141 | } |
lichun | 1cd8b94 | 2020-11-07 01:03:39 +0800 | [diff] [blame] | 142 | if (con->hw_ops->gfx_update) { |
Gerd Hoffmann | 380cd05 | 2013-03-13 14:04:18 +0100 | [diff] [blame] | 143 | con->hw_ops->gfx_update(con->hw); |
Marc-André Lureau | 4d63162 | 2015-08-24 13:20:49 +0200 | [diff] [blame] | 144 | async = con->hw_ops->gfx_update_async; |
| 145 | } |
| 146 | if (!async) { |
| 147 | graphic_hw_update_done(con); |
Gerd Hoffmann | 1dbfa00 | 2013-03-12 13:44:38 +0100 | [diff] [blame] | 148 | } |
pbrook | 9521989 | 2006-04-09 01:06:34 +0000 | [diff] [blame] | 149 | } |
| 150 | |
Marc-André Lureau | 4f2c765 | 2023-08-30 13:37:37 +0400 | [diff] [blame] | 151 | static void graphic_hw_update_bh(void *con) |
| 152 | { |
| 153 | graphic_hw_update(con); |
| 154 | } |
| 155 | |
| 156 | void qemu_console_co_wait_update(QemuConsole *con) |
| 157 | { |
| 158 | if (qemu_co_queue_empty(&con->dump_queue)) { |
| 159 | /* Defer the update, it will restart the pending coroutines */ |
| 160 | aio_bh_schedule_oneshot(qemu_get_aio_context(), |
| 161 | graphic_hw_update_bh, con); |
| 162 | } |
| 163 | qemu_co_queue_wait(&con->dump_queue, NULL); |
| 164 | |
| 165 | } |
| 166 | |
Marc-André Lureau | a9b1e47 | 2021-03-11 11:56:58 +0400 | [diff] [blame] | 167 | static void graphic_hw_gl_unblock_timer(void *opaque) |
| 168 | { |
| 169 | warn_report("console: no gl-unblock within one second"); |
| 170 | } |
| 171 | |
Gerd Hoffmann | bba19b8 | 2015-12-03 12:34:25 +0100 | [diff] [blame] | 172 | void graphic_hw_gl_block(QemuConsole *con, bool block) |
| 173 | { |
Marc-André Lureau | a9b1e47 | 2021-03-11 11:56:58 +0400 | [diff] [blame] | 174 | uint64_t timeout; |
Gerd Hoffmann | f607867 | 2016-09-23 09:50:27 +0200 | [diff] [blame] | 175 | assert(con != NULL); |
| 176 | |
Marc-André Lureau | a4ddc31 | 2021-03-11 11:45:33 +0400 | [diff] [blame] | 177 | if (block) { |
| 178 | con->gl_block++; |
| 179 | } else { |
| 180 | con->gl_block--; |
Gerd Hoffmann | bba19b8 | 2015-12-03 12:34:25 +0100 | [diff] [blame] | 181 | } |
Marc-André Lureau | a4ddc31 | 2021-03-11 11:45:33 +0400 | [diff] [blame] | 182 | assert(con->gl_block >= 0); |
| 183 | if (!con->hw_ops->gl_block) { |
| 184 | return; |
| 185 | } |
| 186 | if ((block && con->gl_block != 1) || (!block && con->gl_block != 0)) { |
| 187 | return; |
| 188 | } |
| 189 | con->hw_ops->gl_block(con->hw, block); |
Marc-André Lureau | a9b1e47 | 2021-03-11 11:56:58 +0400 | [diff] [blame] | 190 | |
| 191 | if (block) { |
| 192 | timeout = qemu_clock_get_ms(QEMU_CLOCK_REALTIME); |
| 193 | timeout += 1000; /* one sec */ |
| 194 | timer_mod(con->gl_unblock_timer, timeout); |
| 195 | } else { |
| 196 | timer_del(con->gl_unblock_timer); |
| 197 | } |
Gerd Hoffmann | bba19b8 | 2015-12-03 12:34:25 +0100 | [diff] [blame] | 198 | } |
| 199 | |
Samuel Thibault | b3cb21b | 2016-12-21 01:38:04 +0100 | [diff] [blame] | 200 | int qemu_console_get_window_id(QemuConsole *con) |
| 201 | { |
| 202 | return con->window_id; |
| 203 | } |
| 204 | |
| 205 | void qemu_console_set_window_id(QemuConsole *con, int window_id) |
| 206 | { |
| 207 | con->window_id = window_id; |
| 208 | } |
| 209 | |
Gerd Hoffmann | 1dbfa00 | 2013-03-12 13:44:38 +0100 | [diff] [blame] | 210 | void graphic_hw_invalidate(QemuConsole *con) |
pbrook | 9521989 | 2006-04-09 01:06:34 +0000 | [diff] [blame] | 211 | { |
Gerd Hoffmann | 1dbfa00 | 2013-03-12 13:44:38 +0100 | [diff] [blame] | 212 | if (!con) { |
| 213 | con = active_console; |
| 214 | } |
Gerd Hoffmann | 380cd05 | 2013-03-13 14:04:18 +0100 | [diff] [blame] | 215 | if (con && con->hw_ops->invalidate) { |
| 216 | con->hw_ops->invalidate(con->hw); |
Gerd Hoffmann | 1dbfa00 | 2013-03-12 13:44:38 +0100 | [diff] [blame] | 217 | } |
pbrook | 9521989 | 2006-04-09 01:06:34 +0000 | [diff] [blame] | 218 | } |
| 219 | |
Gerd Hoffmann | 1dbfa00 | 2013-03-12 13:44:38 +0100 | [diff] [blame] | 220 | void graphic_hw_text_update(QemuConsole *con, console_ch_t *chardata) |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 221 | { |
Gerd Hoffmann | 1dbfa00 | 2013-03-12 13:44:38 +0100 | [diff] [blame] | 222 | if (!con) { |
| 223 | con = active_console; |
| 224 | } |
Gerd Hoffmann | 380cd05 | 2013-03-13 14:04:18 +0100 | [diff] [blame] | 225 | if (con && con->hw_ops->text_update) { |
| 226 | con->hw_ops->text_update(con->hw, chardata); |
| 227 | } |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Marc-André Lureau | 26b032b | 2022-02-17 12:42:20 +0400 | [diff] [blame] | 230 | static void displaychangelistener_gfx_switch(DisplayChangeListener *dcl, |
Marc-André Lureau | c84ab0a | 2022-02-20 23:31:58 +0400 | [diff] [blame] | 231 | struct DisplaySurface *new_surface, |
| 232 | bool update) |
Marc-André Lureau | 26b032b | 2022-02-17 12:42:20 +0400 | [diff] [blame] | 233 | { |
| 234 | if (dcl->ops->dpy_gfx_switch) { |
| 235 | dcl->ops->dpy_gfx_switch(dcl, new_surface); |
| 236 | } |
Marc-André Lureau | c84ab0a | 2022-02-20 23:31:58 +0400 | [diff] [blame] | 237 | |
| 238 | if (update && dcl->ops->dpy_gfx_update) { |
| 239 | dcl->ops->dpy_gfx_update(dcl, 0, 0, |
| 240 | surface_width(new_surface), |
| 241 | surface_height(new_surface)); |
| 242 | } |
Marc-André Lureau | 26b032b | 2022-02-17 12:42:20 +0400 | [diff] [blame] | 243 | } |
| 244 | |
Marc-André Lureau | 589089f | 2022-02-17 15:07:21 +0400 | [diff] [blame] | 245 | static void dpy_gfx_create_texture(QemuConsole *con, DisplaySurface *surface) |
| 246 | { |
| 247 | if (con->gl && con->gl->ops->dpy_gl_ctx_create_texture) { |
| 248 | con->gl->ops->dpy_gl_ctx_create_texture(con->gl, surface); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | static void dpy_gfx_destroy_texture(QemuConsole *con, DisplaySurface *surface) |
| 253 | { |
| 254 | if (con->gl && con->gl->ops->dpy_gl_ctx_destroy_texture) { |
| 255 | con->gl->ops->dpy_gl_ctx_destroy_texture(con->gl, surface); |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | static void dpy_gfx_update_texture(QemuConsole *con, DisplaySurface *surface, |
| 260 | int x, int y, int w, int h) |
| 261 | { |
| 262 | if (con->gl && con->gl->ops->dpy_gl_ctx_update_texture) { |
| 263 | con->gl->ops->dpy_gl_ctx_update_texture(con->gl, surface, x, y, w, h); |
| 264 | } |
| 265 | } |
Marc-André Lureau | 26b032b | 2022-02-17 12:42:20 +0400 | [diff] [blame] | 266 | |
Marc-André Lureau | ebced09 | 2021-02-20 16:23:03 +0400 | [diff] [blame] | 267 | static void displaychangelistener_display_console(DisplayChangeListener *dcl, |
Marc-André Lureau | 4b7b661 | 2022-02-16 20:16:55 +0400 | [diff] [blame] | 268 | QemuConsole *con, |
| 269 | Error **errp) |
Marc-André Lureau | ebced09 | 2021-02-20 16:23:03 +0400 | [diff] [blame] | 270 | { |
| 271 | static const char nodev[] = |
| 272 | "This VM has no graphic display device."; |
| 273 | static DisplaySurface *dummy; |
| 274 | |
Marc-André Lureau | 4b7b661 | 2022-02-16 20:16:55 +0400 | [diff] [blame] | 275 | if (!con || !console_compatible_with(con, dcl, errp)) { |
Marc-André Lureau | ebced09 | 2021-02-20 16:23:03 +0400 | [diff] [blame] | 276 | if (!dummy) { |
| 277 | dummy = qemu_create_placeholder_surface(640, 480, nodev); |
| 278 | } |
Marc-André Lureau | 589089f | 2022-02-17 15:07:21 +0400 | [diff] [blame] | 279 | if (con) { |
| 280 | dpy_gfx_create_texture(con, dummy); |
| 281 | } |
Marc-André Lureau | c84ab0a | 2022-02-20 23:31:58 +0400 | [diff] [blame] | 282 | displaychangelistener_gfx_switch(dcl, dummy, TRUE); |
Marc-André Lureau | ebced09 | 2021-02-20 16:23:03 +0400 | [diff] [blame] | 283 | return; |
| 284 | } |
| 285 | |
Marc-André Lureau | e1c676a | 2022-02-20 23:45:38 +0400 | [diff] [blame] | 286 | dpy_gfx_create_texture(con, con->surface); |
| 287 | displaychangelistener_gfx_switch(dcl, con->surface, |
| 288 | con->scanout.kind == SCANOUT_SURFACE); |
| 289 | |
Marc-André Lureau | ebced09 | 2021-02-20 16:23:03 +0400 | [diff] [blame] | 290 | if (con->scanout.kind == SCANOUT_DMABUF && |
| 291 | displaychangelistener_has_dmabuf(dcl)) { |
| 292 | dcl->ops->dpy_gl_scanout_dmabuf(dcl, con->scanout.dmabuf); |
| 293 | } else if (con->scanout.kind == SCANOUT_TEXTURE && |
| 294 | dcl->ops->dpy_gl_scanout_texture) { |
| 295 | dcl->ops->dpy_gl_scanout_texture(dcl, |
| 296 | con->scanout.texture.backing_id, |
| 297 | con->scanout.texture.backing_y_0_top, |
| 298 | con->scanout.texture.backing_width, |
| 299 | con->scanout.texture.backing_height, |
| 300 | con->scanout.texture.x, |
| 301 | con->scanout.texture.y, |
| 302 | con->scanout.texture.width, |
Marc-André Lureau | bf41ab6 | 2023-06-06 15:56:56 +0400 | [diff] [blame] | 303 | con->scanout.texture.height, |
| 304 | con->scanout.texture.d3d_tex2d); |
Marc-André Lureau | ebced09 | 2021-02-20 16:23:03 +0400 | [diff] [blame] | 305 | } |
Marc-André Lureau | ebced09 | 2021-02-20 16:23:03 +0400 | [diff] [blame] | 306 | } |
| 307 | |
bellard | e7f0ad5 | 2004-07-14 17:28:59 +0000 | [diff] [blame] | 308 | void console_select(unsigned int index) |
| 309 | { |
Gerd Hoffmann | 284d1c6 | 2013-03-15 15:45:54 +0100 | [diff] [blame] | 310 | DisplayChangeListener *dcl; |
Gerd Hoffmann | 76ffb0b | 2012-09-28 13:24:17 +0200 | [diff] [blame] | 311 | QemuConsole *s; |
pbrook | 6d6f7c2 | 2006-03-11 15:35:30 +0000 | [diff] [blame] | 312 | |
Gerd Hoffmann | 437fe10 | 2013-03-07 16:04:52 +0100 | [diff] [blame] | 313 | trace_console_select(index); |
Gerd Hoffmann | 284d1c6 | 2013-03-15 15:45:54 +0100 | [diff] [blame] | 314 | s = qemu_console_lookup_by_index(index); |
bellard | e7f0ad5 | 2004-07-14 17:28:59 +0000 | [diff] [blame] | 315 | if (s) { |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 316 | DisplayState *ds = s->ds; |
Jan Kiszka | bf1bed8 | 2012-07-10 22:00:55 +0200 | [diff] [blame] | 317 | |
bellard | e7f0ad5 | 2004-07-14 17:28:59 +0000 | [diff] [blame] | 318 | active_console = s; |
Marc-André Lureau | 074b240 | 2023-08-30 13:37:40 +0400 | [diff] [blame] | 319 | QLIST_FOREACH (dcl, &ds->listeners, next) { |
| 320 | if (dcl->con != NULL) { |
| 321 | continue; |
Gerd Hoffmann | 2e5567c | 2018-03-08 17:18:03 +0100 | [diff] [blame] | 322 | } |
Marc-André Lureau | 074b240 | 2023-08-30 13:37:40 +0400 | [diff] [blame] | 323 | displaychangelistener_display_console(dcl, s, NULL); |
Gerd Hoffmann | a93a4a2 | 2012-09-28 15:02:08 +0200 | [diff] [blame] | 324 | } |
Marc-André Lureau | b2bb9cc | 2023-08-30 13:38:02 +0400 | [diff] [blame] | 325 | |
| 326 | if (QEMU_IS_TEXT_CONSOLE(s)) { |
Marc-André Lureau | f7ce755 | 2023-08-30 13:38:22 +0400 | [diff] [blame] | 327 | qemu_text_console_select(QEMU_TEXT_CONSOLE(s)); |
Marc-André Lureau | b2bb9cc | 2023-08-30 13:38:02 +0400 | [diff] [blame] | 328 | } |
bellard | e7f0ad5 | 2004-07-14 17:28:59 +0000 | [diff] [blame] | 329 | } |
| 330 | } |
| 331 | |
Marc-André Lureau | f7ce755 | 2023-08-30 13:38:22 +0400 | [diff] [blame] | 332 | void qemu_text_console_put_keysym(QemuTextConsole *s, int keysym) |
| 333 | { |
| 334 | if (!s) { |
| 335 | if (!QEMU_IS_TEXT_CONSOLE(active_console)) { |
| 336 | return; |
| 337 | } |
| 338 | s = QEMU_TEXT_CONSOLE(active_console); |
| 339 | } |
| 340 | |
| 341 | qemu_text_console_handle_keysym(s, keysym); |
| 342 | } |
| 343 | |
Eric Blake | 7fb1cf1 | 2015-11-18 01:52:57 -0700 | [diff] [blame] | 344 | static const int qcode_to_keysym[Q_KEY_CODE__MAX] = { |
Gerd Hoffmann | 50ef467 | 2014-05-27 09:28:38 +0200 | [diff] [blame] | 345 | [Q_KEY_CODE_UP] = QEMU_KEY_UP, |
| 346 | [Q_KEY_CODE_DOWN] = QEMU_KEY_DOWN, |
| 347 | [Q_KEY_CODE_RIGHT] = QEMU_KEY_RIGHT, |
| 348 | [Q_KEY_CODE_LEFT] = QEMU_KEY_LEFT, |
| 349 | [Q_KEY_CODE_HOME] = QEMU_KEY_HOME, |
| 350 | [Q_KEY_CODE_END] = QEMU_KEY_END, |
| 351 | [Q_KEY_CODE_PGUP] = QEMU_KEY_PAGEUP, |
| 352 | [Q_KEY_CODE_PGDN] = QEMU_KEY_PAGEDOWN, |
| 353 | [Q_KEY_CODE_DELETE] = QEMU_KEY_DELETE, |
Cal Peake | df6322a | 2022-08-11 18:01:38 -0400 | [diff] [blame] | 354 | [Q_KEY_CODE_TAB] = QEMU_KEY_TAB, |
Thomas Huth | 344aa28 | 2016-08-11 09:21:00 +0200 | [diff] [blame] | 355 | [Q_KEY_CODE_BACKSPACE] = QEMU_KEY_BACKSPACE, |
Gerd Hoffmann | 50ef467 | 2014-05-27 09:28:38 +0200 | [diff] [blame] | 356 | }; |
| 357 | |
Gerd Hoffmann | da024b1 | 2018-03-21 14:50:36 +0100 | [diff] [blame] | 358 | static const int ctrl_qcode_to_keysym[Q_KEY_CODE__MAX] = { |
| 359 | [Q_KEY_CODE_UP] = QEMU_KEY_CTRL_UP, |
| 360 | [Q_KEY_CODE_DOWN] = QEMU_KEY_CTRL_DOWN, |
| 361 | [Q_KEY_CODE_RIGHT] = QEMU_KEY_CTRL_RIGHT, |
| 362 | [Q_KEY_CODE_LEFT] = QEMU_KEY_CTRL_LEFT, |
| 363 | [Q_KEY_CODE_HOME] = QEMU_KEY_CTRL_HOME, |
| 364 | [Q_KEY_CODE_END] = QEMU_KEY_CTRL_END, |
| 365 | [Q_KEY_CODE_PGUP] = QEMU_KEY_CTRL_PAGEUP, |
| 366 | [Q_KEY_CODE_PGDN] = QEMU_KEY_CTRL_PAGEDOWN, |
| 367 | }; |
| 368 | |
Marc-André Lureau | cc6ba2c | 2023-08-30 13:38:20 +0400 | [diff] [blame] | 369 | bool qemu_text_console_put_qcode(QemuTextConsole *s, int qcode, bool ctrl) |
Gerd Hoffmann | 50ef467 | 2014-05-27 09:28:38 +0200 | [diff] [blame] | 370 | { |
| 371 | int keysym; |
| 372 | |
Gerd Hoffmann | da024b1 | 2018-03-21 14:50:36 +0100 | [diff] [blame] | 373 | keysym = ctrl ? ctrl_qcode_to_keysym[qcode] : qcode_to_keysym[qcode]; |
Gerd Hoffmann | 50ef467 | 2014-05-27 09:28:38 +0200 | [diff] [blame] | 374 | if (keysym == 0) { |
| 375 | return false; |
| 376 | } |
Marc-André Lureau | cc6ba2c | 2023-08-30 13:38:20 +0400 | [diff] [blame] | 377 | qemu_text_console_put_keysym(s, keysym); |
Gerd Hoffmann | 50ef467 | 2014-05-27 09:28:38 +0200 | [diff] [blame] | 378 | return true; |
| 379 | } |
| 380 | |
Marc-André Lureau | cc6ba2c | 2023-08-30 13:38:20 +0400 | [diff] [blame] | 381 | void qemu_text_console_put_string(QemuTextConsole *s, const char *str, int len) |
Gerd Hoffmann | bdef972 | 2014-05-27 09:32:36 +0200 | [diff] [blame] | 382 | { |
| 383 | int i; |
| 384 | |
| 385 | for (i = 0; i < len && str[i]; i++) { |
Marc-André Lureau | cc6ba2c | 2023-08-30 13:38:20 +0400 | [diff] [blame] | 386 | qemu_text_console_put_keysym(s, str[i]); |
Gerd Hoffmann | bdef972 | 2014-05-27 09:32:36 +0200 | [diff] [blame] | 387 | } |
| 388 | } |
| 389 | |
Marc-André Lureau | 098d57e | 2023-08-30 13:37:52 +0400 | [diff] [blame] | 390 | static void |
Marc-André Lureau | c105d60 | 2023-08-30 13:37:54 +0400 | [diff] [blame] | 391 | qemu_console_register(QemuConsole *c) |
bellard | e7f0ad5 | 2004-07-14 17:28:59 +0000 | [diff] [blame] | 392 | { |
pbrook | 9521989 | 2006-04-09 01:06:34 +0000 | [diff] [blame] | 393 | int i; |
bellard | e7f0ad5 | 2004-07-14 17:28:59 +0000 | [diff] [blame] | 394 | |
Marc-André Lureau | c105d60 | 2023-08-30 13:37:54 +0400 | [diff] [blame] | 395 | if (!active_console || (!QEMU_IS_GRAPHIC_CONSOLE(active_console) && |
| 396 | QEMU_IS_GRAPHIC_CONSOLE(c))) { |
Marc-André Lureau | 098d57e | 2023-08-30 13:37:52 +0400 | [diff] [blame] | 397 | active_console = c; |
ths | af3a903 | 2007-07-11 23:14:59 +0000 | [diff] [blame] | 398 | } |
Gerd Hoffmann | a1d2db0 | 2014-05-26 10:36:35 +0200 | [diff] [blame] | 399 | |
Gerd Hoffmann | cd6cd8f | 2018-05-07 11:54:24 +0200 | [diff] [blame] | 400 | if (QTAILQ_EMPTY(&consoles)) { |
Marc-André Lureau | 098d57e | 2023-08-30 13:37:52 +0400 | [diff] [blame] | 401 | c->index = 0; |
| 402 | QTAILQ_INSERT_TAIL(&consoles, c, next); |
Marc-André Lureau | c105d60 | 2023-08-30 13:37:54 +0400 | [diff] [blame] | 403 | } else if (!QEMU_IS_GRAPHIC_CONSOLE(c) || phase_check(PHASE_MACHINE_READY)) { |
Paolo Bonzini | eae3eb3 | 2018-12-06 13:10:34 +0100 | [diff] [blame] | 404 | QemuConsole *last = QTAILQ_LAST(&consoles); |
Marc-André Lureau | 098d57e | 2023-08-30 13:37:52 +0400 | [diff] [blame] | 405 | c->index = last->index + 1; |
| 406 | QTAILQ_INSERT_TAIL(&consoles, c, next); |
pbrook | 9521989 | 2006-04-09 01:06:34 +0000 | [diff] [blame] | 407 | } else { |
Gerd Hoffmann | 9588d67 | 2018-03-13 11:17:29 -0600 | [diff] [blame] | 408 | /* |
| 409 | * HACK: Put graphical consoles before text consoles. |
| 410 | * |
| 411 | * Only do that for coldplugged devices. After initial device |
| 412 | * initialization we will not renumber the consoles any more. |
| 413 | */ |
Marc-André Lureau | 098d57e | 2023-08-30 13:37:52 +0400 | [diff] [blame] | 414 | QemuConsole *it = QTAILQ_FIRST(&consoles); |
Gerd Hoffmann | cd6cd8f | 2018-05-07 11:54:24 +0200 | [diff] [blame] | 415 | |
Marc-André Lureau | c105d60 | 2023-08-30 13:37:54 +0400 | [diff] [blame] | 416 | while (QTAILQ_NEXT(it, next) != NULL && QEMU_IS_GRAPHIC_CONSOLE(it)) { |
Marc-André Lureau | 098d57e | 2023-08-30 13:37:52 +0400 | [diff] [blame] | 417 | it = QTAILQ_NEXT(it, next); |
pbrook | 9521989 | 2006-04-09 01:06:34 +0000 | [diff] [blame] | 418 | } |
Marc-André Lureau | c105d60 | 2023-08-30 13:37:54 +0400 | [diff] [blame] | 419 | if (QEMU_IS_GRAPHIC_CONSOLE(it)) { |
Gerd Hoffmann | cd6cd8f | 2018-05-07 11:54:24 +0200 | [diff] [blame] | 420 | /* have no text consoles */ |
Marc-André Lureau | 098d57e | 2023-08-30 13:37:52 +0400 | [diff] [blame] | 421 | c->index = it->index + 1; |
| 422 | QTAILQ_INSERT_AFTER(&consoles, it, c, next); |
Gerd Hoffmann | cd6cd8f | 2018-05-07 11:54:24 +0200 | [diff] [blame] | 423 | } else { |
Marc-André Lureau | 098d57e | 2023-08-30 13:37:52 +0400 | [diff] [blame] | 424 | c->index = it->index; |
| 425 | QTAILQ_INSERT_BEFORE(it, c, next); |
Gerd Hoffmann | cd6cd8f | 2018-05-07 11:54:24 +0200 | [diff] [blame] | 426 | /* renumber text consoles */ |
Marc-André Lureau | 098d57e | 2023-08-30 13:37:52 +0400 | [diff] [blame] | 427 | for (i = c->index + 1; it != NULL; it = QTAILQ_NEXT(it, next), i++) { |
| 428 | it->index = i; |
Gerd Hoffmann | cd6cd8f | 2018-05-07 11:54:24 +0200 | [diff] [blame] | 429 | } |
| 430 | } |
pbrook | 9521989 | 2006-04-09 01:06:34 +0000 | [diff] [blame] | 431 | } |
bellard | e7f0ad5 | 2004-07-14 17:28:59 +0000 | [diff] [blame] | 432 | } |
| 433 | |
Marc-André Lureau | e265917 | 2023-08-30 13:37:51 +0400 | [diff] [blame] | 434 | static void |
| 435 | qemu_console_finalize(Object *obj) |
| 436 | { |
Marc-André Lureau | cfde05d | 2023-08-30 13:37:59 +0400 | [diff] [blame] | 437 | QemuConsole *c = QEMU_CONSOLE(obj); |
| 438 | |
Marc-André Lureau | 463c6b1 | 2023-08-30 13:38:01 +0400 | [diff] [blame] | 439 | /* TODO: check this code path, and unregister from consoles */ |
Marc-André Lureau | 463c6b1 | 2023-08-30 13:38:01 +0400 | [diff] [blame] | 440 | g_clear_pointer(&c->surface, qemu_free_displaysurface); |
| 441 | g_clear_pointer(&c->gl_unblock_timer, timer_free); |
Marc-André Lureau | cfde05d | 2023-08-30 13:37:59 +0400 | [diff] [blame] | 442 | g_clear_pointer(&c->ui_timer, timer_free); |
Marc-André Lureau | 098d57e | 2023-08-30 13:37:52 +0400 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | static void |
Marc-André Lureau | e265917 | 2023-08-30 13:37:51 +0400 | [diff] [blame] | 446 | qemu_console_class_init(ObjectClass *oc, void *data) |
| 447 | { |
| 448 | } |
| 449 | |
| 450 | static void |
| 451 | qemu_console_init(Object *obj) |
| 452 | { |
Marc-André Lureau | 098d57e | 2023-08-30 13:37:52 +0400 | [diff] [blame] | 453 | QemuConsole *c = QEMU_CONSOLE(obj); |
| 454 | DisplayState *ds = get_alloc_displaystate(); |
| 455 | |
| 456 | qemu_co_queue_init(&c->dump_queue); |
| 457 | c->ds = ds; |
| 458 | c->window_id = -1; |
Marc-André Lureau | cfde05d | 2023-08-30 13:37:59 +0400 | [diff] [blame] | 459 | c->ui_timer = timer_new_ms(QEMU_CLOCK_REALTIME, |
| 460 | dpy_set_ui_info_timer, c); |
Marc-André Lureau | ba0ec5c | 2023-08-30 13:37:55 +0400 | [diff] [blame] | 461 | qemu_console_register(c); |
Marc-André Lureau | 098d57e | 2023-08-30 13:37:52 +0400 | [diff] [blame] | 462 | } |
| 463 | |
Marc-André Lureau | b208f74 | 2023-08-30 13:37:53 +0400 | [diff] [blame] | 464 | static void |
| 465 | qemu_graphic_console_finalize(Object *obj) |
| 466 | { |
Marc-André Lureau | 58d5870 | 2023-08-30 13:38:03 +0400 | [diff] [blame] | 467 | QemuGraphicConsole *c = QEMU_GRAPHIC_CONSOLE(obj); |
| 468 | |
| 469 | g_clear_pointer(&c->device, object_unref); |
| 470 | } |
| 471 | |
| 472 | static void |
| 473 | qemu_graphic_console_prop_get_head(Object *obj, Visitor *v, const char *name, |
| 474 | void *opaque, Error **errp) |
| 475 | { |
| 476 | QemuGraphicConsole *c = QEMU_GRAPHIC_CONSOLE(obj); |
| 477 | |
| 478 | visit_type_uint32(v, name, &c->head, errp); |
Marc-André Lureau | b208f74 | 2023-08-30 13:37:53 +0400 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | static void |
| 482 | qemu_graphic_console_class_init(ObjectClass *oc, void *data) |
| 483 | { |
Marc-André Lureau | 58d5870 | 2023-08-30 13:38:03 +0400 | [diff] [blame] | 484 | object_class_property_add_link(oc, "device", TYPE_DEVICE, |
| 485 | offsetof(QemuGraphicConsole, device), |
| 486 | object_property_allow_set_link, |
| 487 | OBJ_PROP_LINK_STRONG); |
| 488 | object_class_property_add(oc, "head", "uint32", |
| 489 | qemu_graphic_console_prop_get_head, |
| 490 | NULL, NULL, NULL); |
Marc-André Lureau | b208f74 | 2023-08-30 13:37:53 +0400 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | static void |
| 494 | qemu_graphic_console_init(Object *obj) |
| 495 | { |
| 496 | } |
| 497 | |
Marc-André Lureau | 09b4c19 | 2023-06-06 15:56:46 +0400 | [diff] [blame] | 498 | #ifdef WIN32 |
| 499 | void qemu_displaysurface_win32_set_handle(DisplaySurface *surface, |
| 500 | HANDLE h, uint32_t offset) |
| 501 | { |
| 502 | assert(!surface->handle); |
| 503 | |
| 504 | surface->handle = h; |
| 505 | surface->handle_offset = offset; |
| 506 | } |
| 507 | |
| 508 | static void |
| 509 | win32_pixman_image_destroy(pixman_image_t *image, void *data) |
| 510 | { |
| 511 | DisplaySurface *surface = data; |
| 512 | |
| 513 | if (!surface->handle) { |
| 514 | return; |
| 515 | } |
| 516 | |
| 517 | assert(surface->handle_offset == 0); |
| 518 | |
| 519 | qemu_win32_map_free( |
| 520 | pixman_image_get_data(surface->image), |
| 521 | surface->handle, |
| 522 | &error_warn |
| 523 | ); |
| 524 | } |
| 525 | #endif |
| 526 | |
Gerd Hoffmann | da229ef | 2013-02-28 10:48:02 +0100 | [diff] [blame] | 527 | DisplaySurface *qemu_create_displaysurface(int width, int height) |
Gerd Hoffmann | 537a439 | 2012-09-27 11:06:36 +0200 | [diff] [blame] | 528 | { |
Marc-André Lureau | 09b4c19 | 2023-06-06 15:56:46 +0400 | [diff] [blame] | 529 | DisplaySurface *surface; |
| 530 | void *bits = NULL; |
| 531 | #ifdef WIN32 |
| 532 | HANDLE handle = NULL; |
| 533 | #endif |
Gerd Hoffmann | da229ef | 2013-02-28 10:48:02 +0100 | [diff] [blame] | 534 | |
Marc-André Lureau | 09b4c19 | 2023-06-06 15:56:46 +0400 | [diff] [blame] | 535 | trace_displaysurface_create(width, height); |
| 536 | |
| 537 | #ifdef WIN32 |
| 538 | bits = qemu_win32_map_alloc(width * height * 4, &handle, &error_abort); |
| 539 | #endif |
| 540 | |
| 541 | surface = qemu_create_displaysurface_from( |
| 542 | width, height, |
| 543 | PIXMAN_x8r8g8b8, |
| 544 | width * 4, bits |
| 545 | ); |
Marc-André Lureau | eb69442 | 2021-03-12 14:00:42 +0400 | [diff] [blame] | 546 | surface->flags = QEMU_ALLOCATED_FLAG; |
| 547 | |
Marc-André Lureau | 09b4c19 | 2023-06-06 15:56:46 +0400 | [diff] [blame] | 548 | #ifdef WIN32 |
| 549 | qemu_displaysurface_win32_set_handle(surface, handle, 0); |
| 550 | #endif |
Gerd Hoffmann | 537a439 | 2012-09-27 11:06:36 +0200 | [diff] [blame] | 551 | return surface; |
| 552 | } |
| 553 | |
Gerd Hoffmann | 30f1e66 | 2014-06-18 11:03:15 +0200 | [diff] [blame] | 554 | DisplaySurface *qemu_create_displaysurface_from(int width, int height, |
| 555 | pixman_format_code_t format, |
| 556 | int linesize, uint8_t *data) |
Paolo Bonzini | 98b5008 | 2010-02-11 00:29:57 +0100 | [diff] [blame] | 557 | { |
Gerd Hoffmann | 69c7777 | 2012-09-26 15:20:05 +0200 | [diff] [blame] | 558 | DisplaySurface *surface = g_new0(DisplaySurface, 1); |
Paolo Bonzini | 98b5008 | 2010-02-11 00:29:57 +0100 | [diff] [blame] | 559 | |
Gerd Hoffmann | 30f1e66 | 2014-06-18 11:03:15 +0200 | [diff] [blame] | 560 | trace_displaysurface_create_from(surface, width, height, format); |
Marc-André Lureau | ff174c6 | 2023-08-30 13:38:21 +0400 | [diff] [blame] | 561 | surface->image = pixman_image_create_bits(format, |
Gerd Hoffmann | 69c7777 | 2012-09-26 15:20:05 +0200 | [diff] [blame] | 562 | width, height, |
| 563 | (void *)data, linesize); |
| 564 | assert(surface->image != NULL); |
Marc-André Lureau | 09b4c19 | 2023-06-06 15:56:46 +0400 | [diff] [blame] | 565 | #ifdef WIN32 |
| 566 | pixman_image_set_destroy_function(surface->image, |
| 567 | win32_pixman_image_destroy, surface); |
| 568 | #endif |
Gerd Hoffmann | 69c7777 | 2012-09-26 15:20:05 +0200 | [diff] [blame] | 569 | |
Paolo Bonzini | 98b5008 | 2010-02-11 00:29:57 +0100 | [diff] [blame] | 570 | return surface; |
| 571 | } |
| 572 | |
Gerd Hoffmann | ca58b45 | 2016-04-01 10:27:20 +0200 | [diff] [blame] | 573 | DisplaySurface *qemu_create_displaysurface_pixman(pixman_image_t *image) |
| 574 | { |
| 575 | DisplaySurface *surface = g_new0(DisplaySurface, 1); |
| 576 | |
| 577 | trace_displaysurface_create_pixman(surface); |
Gerd Hoffmann | ca58b45 | 2016-04-01 10:27:20 +0200 | [diff] [blame] | 578 | surface->image = pixman_image_ref(image); |
| 579 | |
| 580 | return surface; |
| 581 | } |
| 582 | |
Akihiko Odaki | b5a087b | 2021-02-25 19:13:14 +0900 | [diff] [blame] | 583 | DisplaySurface *qemu_create_placeholder_surface(int w, int h, |
| 584 | const char *msg) |
Gerd Hoffmann | d3002b0 | 2013-04-25 09:33:19 +0200 | [diff] [blame] | 585 | { |
Gerd Hoffmann | 521a580 | 2013-04-25 12:10:45 +0200 | [diff] [blame] | 586 | DisplaySurface *surface = qemu_create_displaysurface(w, h); |
Marc-André Lureau | 1ece677 | 2023-08-30 13:38:10 +0400 | [diff] [blame] | 587 | pixman_color_t bg = QEMU_PIXMAN_COLOR_BLACK; |
| 588 | pixman_color_t fg = QEMU_PIXMAN_COLOR_GRAY; |
Gerd Hoffmann | d3002b0 | 2013-04-25 09:33:19 +0200 | [diff] [blame] | 589 | pixman_image_t *glyph; |
| 590 | int len, x, y, i; |
| 591 | |
| 592 | len = strlen(msg); |
Gerd Hoffmann | 521a580 | 2013-04-25 12:10:45 +0200 | [diff] [blame] | 593 | x = (w / FONT_WIDTH - len) / 2; |
| 594 | y = (h / FONT_HEIGHT - 1) / 2; |
Gerd Hoffmann | d3002b0 | 2013-04-25 09:33:19 +0200 | [diff] [blame] | 595 | for (i = 0; i < len; i++) { |
| 596 | glyph = qemu_pixman_glyph_from_vgafont(FONT_HEIGHT, vgafont16, msg[i]); |
| 597 | qemu_pixman_glyph_render(glyph, surface->image, &fg, &bg, |
| 598 | x+i, y, FONT_WIDTH, FONT_HEIGHT); |
| 599 | qemu_pixman_image_unref(glyph); |
| 600 | } |
Akihiko Odaki | b5a087b | 2021-02-25 19:13:14 +0900 | [diff] [blame] | 601 | surface->flags |= QEMU_PLACEHOLDER_FLAG; |
Gerd Hoffmann | d3002b0 | 2013-04-25 09:33:19 +0200 | [diff] [blame] | 602 | return surface; |
| 603 | } |
| 604 | |
Gerd Hoffmann | da229ef | 2013-02-28 10:48:02 +0100 | [diff] [blame] | 605 | void qemu_free_displaysurface(DisplaySurface *surface) |
Paolo Bonzini | 98b5008 | 2010-02-11 00:29:57 +0100 | [diff] [blame] | 606 | { |
Gerd Hoffmann | da229ef | 2013-02-28 10:48:02 +0100 | [diff] [blame] | 607 | if (surface == NULL) { |
Paolo Bonzini | 98b5008 | 2010-02-11 00:29:57 +0100 | [diff] [blame] | 608 | return; |
Gerd Hoffmann | 187cd1d | 2012-09-26 07:46:20 +0200 | [diff] [blame] | 609 | } |
Gerd Hoffmann | da229ef | 2013-02-28 10:48:02 +0100 | [diff] [blame] | 610 | trace_displaysurface_free(surface); |
| 611 | qemu_pixman_image_unref(surface->image); |
| 612 | g_free(surface); |
Paolo Bonzini | 98b5008 | 2010-02-11 00:29:57 +0100 | [diff] [blame] | 613 | } |
| 614 | |
Gerd Hoffmann | 06020b9 | 2014-07-11 13:56:51 +0200 | [diff] [blame] | 615 | bool console_has_gl(QemuConsole *con) |
| 616 | { |
| 617 | return con->gl != NULL; |
| 618 | } |
| 619 | |
Marc-André Lureau | d0e137b | 2021-02-04 14:52:24 +0400 | [diff] [blame] | 620 | static bool displaychangelistener_has_dmabuf(DisplayChangeListener *dcl) |
| 621 | { |
| 622 | if (dcl->ops->dpy_has_dmabuf) { |
| 623 | return dcl->ops->dpy_has_dmabuf(dcl); |
| 624 | } |
| 625 | |
| 626 | if (dcl->ops->dpy_gl_scanout_dmabuf) { |
| 627 | return true; |
| 628 | } |
| 629 | |
| 630 | return false; |
| 631 | } |
| 632 | |
Marc-André Lureau | 4b7b661 | 2022-02-16 20:16:55 +0400 | [diff] [blame] | 633 | static bool console_compatible_with(QemuConsole *con, |
| 634 | DisplayChangeListener *dcl, Error **errp) |
Marc-André Lureau | 5983fdf | 2021-02-04 14:52:25 +0400 | [diff] [blame] | 635 | { |
Marc-André Lureau | 5983fdf | 2021-02-04 14:52:25 +0400 | [diff] [blame] | 636 | int flags; |
| 637 | |
| 638 | flags = con->hw_ops->get_flags ? con->hw_ops->get_flags(con->hw) : 0; |
| 639 | |
Marc-André Lureau | a62c4a1 | 2022-02-16 19:33:37 +0400 | [diff] [blame] | 640 | if (console_has_gl(con) && |
| 641 | !con->gl->ops->dpy_gl_ctx_is_compatible_dcl(con->gl, dcl)) { |
Marc-André Lureau | 398d1c9 | 2022-02-16 17:35:28 +0400 | [diff] [blame] | 642 | error_setg(errp, "Display %s is incompatible with the GL context", |
| 643 | dcl->ops->dpy_name); |
| 644 | return false; |
| 645 | } |
| 646 | |
Marc-André Lureau | 5983fdf | 2021-02-04 14:52:25 +0400 | [diff] [blame] | 647 | if (flags & GRAPHIC_FLAGS_GL && |
| 648 | !console_has_gl(con)) { |
| 649 | error_setg(errp, "The console requires a GL context."); |
| 650 | return false; |
| 651 | |
| 652 | } |
| 653 | |
| 654 | if (flags & GRAPHIC_FLAGS_DMABUF && |
| 655 | !displaychangelistener_has_dmabuf(dcl)) { |
| 656 | error_setg(errp, "The console requires display DMABUF support."); |
| 657 | return false; |
| 658 | } |
| 659 | |
| 660 | return true; |
| 661 | } |
| 662 | |
Bilal Elmoussaoui | b659678 | 2023-06-19 11:53:36 +0200 | [diff] [blame] | 663 | void console_handle_touch_event(QemuConsole *con, |
| 664 | struct touch_slot touch_slots[INPUT_EVENT_SLOTS_MAX], |
| 665 | uint64_t num_slot, |
| 666 | int width, int height, |
| 667 | double x, double y, |
| 668 | InputMultiTouchType type, |
| 669 | Error **errp) |
| 670 | { |
| 671 | struct touch_slot *slot; |
| 672 | bool needs_sync = false; |
| 673 | int update; |
| 674 | int i; |
| 675 | |
| 676 | if (num_slot >= INPUT_EVENT_SLOTS_MAX) { |
| 677 | error_setg(errp, |
| 678 | "Unexpected touch slot number: % " PRId64" >= %d", |
| 679 | num_slot, INPUT_EVENT_SLOTS_MAX); |
| 680 | return; |
| 681 | } |
| 682 | |
| 683 | slot = &touch_slots[num_slot]; |
| 684 | slot->x = x; |
| 685 | slot->y = y; |
| 686 | |
| 687 | if (type == INPUT_MULTI_TOUCH_TYPE_BEGIN) { |
| 688 | slot->tracking_id = num_slot; |
| 689 | } |
| 690 | |
| 691 | for (i = 0; i < INPUT_EVENT_SLOTS_MAX; ++i) { |
| 692 | if (i == num_slot) { |
| 693 | update = type; |
| 694 | } else { |
| 695 | update = INPUT_MULTI_TOUCH_TYPE_UPDATE; |
| 696 | } |
| 697 | |
| 698 | slot = &touch_slots[i]; |
| 699 | |
| 700 | if (slot->tracking_id == -1) { |
| 701 | continue; |
| 702 | } |
| 703 | |
| 704 | if (update == INPUT_MULTI_TOUCH_TYPE_END) { |
| 705 | slot->tracking_id = -1; |
| 706 | qemu_input_queue_mtt(con, update, i, slot->tracking_id); |
| 707 | needs_sync = true; |
| 708 | } else { |
| 709 | qemu_input_queue_mtt(con, update, i, slot->tracking_id); |
| 710 | qemu_input_queue_btn(con, INPUT_BUTTON_TOUCH, true); |
| 711 | qemu_input_queue_mtt_abs(con, |
| 712 | INPUT_AXIS_X, (int) slot->x, |
| 713 | 0, width, |
| 714 | i, slot->tracking_id); |
| 715 | qemu_input_queue_mtt_abs(con, |
| 716 | INPUT_AXIS_Y, (int) slot->y, |
| 717 | 0, height, |
| 718 | i, slot->tracking_id); |
| 719 | needs_sync = true; |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | if (needs_sync) { |
| 724 | qemu_input_event_sync(); |
| 725 | } |
| 726 | } |
| 727 | |
Marc-André Lureau | 5e79d51 | 2021-10-09 23:48:46 +0400 | [diff] [blame] | 728 | void qemu_console_set_display_gl_ctx(QemuConsole *con, DisplayGLCtx *gl) |
Marc-André Lureau | 4f41814 | 2021-01-25 14:53:18 +0400 | [diff] [blame] | 729 | { |
| 730 | /* display has opengl support */ |
Marc-André Lureau | 5e79d51 | 2021-10-09 23:48:46 +0400 | [diff] [blame] | 731 | assert(con); |
| 732 | if (con->gl) { |
| 733 | error_report("The console already has an OpenGL context."); |
Marc-André Lureau | 4f41814 | 2021-01-25 14:53:18 +0400 | [diff] [blame] | 734 | exit(1); |
| 735 | } |
Marc-André Lureau | 5e79d51 | 2021-10-09 23:48:46 +0400 | [diff] [blame] | 736 | con->gl = gl; |
| 737 | } |
| 738 | |
Marc-André Lureau | 58d5870 | 2023-08-30 13:38:03 +0400 | [diff] [blame] | 739 | static void |
| 740 | dcl_set_graphic_cursor(DisplayChangeListener *dcl, QemuGraphicConsole *con) |
| 741 | { |
| 742 | if (con && con->cursor && dcl->ops->dpy_cursor_define) { |
| 743 | dcl->ops->dpy_cursor_define(dcl, con->cursor); |
| 744 | } |
| 745 | if (con && dcl->ops->dpy_mouse_set) { |
| 746 | dcl->ops->dpy_mouse_set(dcl, con->cursor_x, con->cursor_y, con->cursor_on); |
| 747 | } |
| 748 | } |
Marc-André Lureau | 6f11081 | 2023-08-30 13:38:23 +0400 | [diff] [blame] | 749 | |
Gerd Hoffmann | 5209089 | 2013-04-23 15:44:31 +0200 | [diff] [blame] | 750 | void register_displaychangelistener(DisplayChangeListener *dcl) |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 751 | { |
Gerd Hoffmann | 284d1c6 | 2013-03-15 15:45:54 +0100 | [diff] [blame] | 752 | QemuConsole *con; |
| 753 | |
Marc-André Lureau | e0665c3 | 2017-04-06 14:05:12 +0200 | [diff] [blame] | 754 | assert(!dcl->ds); |
| 755 | |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 756 | trace_displaychangelistener_register(dcl, dcl->ops->dpy_name); |
Gerd Hoffmann | 5209089 | 2013-04-23 15:44:31 +0200 | [diff] [blame] | 757 | dcl->ds = get_alloc_displaystate(); |
| 758 | QLIST_INSERT_HEAD(&dcl->ds->listeners, dcl, next); |
| 759 | gui_setup_refresh(dcl->ds); |
Gerd Hoffmann | 284d1c6 | 2013-03-15 15:45:54 +0100 | [diff] [blame] | 760 | if (dcl->con) { |
| 761 | dcl->con->dcls++; |
| 762 | con = dcl->con; |
| 763 | } else { |
| 764 | con = active_console; |
| 765 | } |
Marc-André Lureau | 4b7b661 | 2022-02-16 20:16:55 +0400 | [diff] [blame] | 766 | displaychangelistener_display_console(dcl, con, dcl->con ? &error_fatal : NULL); |
Marc-André Lureau | 58d5870 | 2023-08-30 13:38:03 +0400 | [diff] [blame] | 767 | if (QEMU_IS_GRAPHIC_CONSOLE(con)) { |
| 768 | dcl_set_graphic_cursor(dcl, QEMU_GRAPHIC_CONSOLE(con)); |
Marc-André Lureau | 6effaa1 | 2023-01-17 15:40:58 +0400 | [diff] [blame] | 769 | } |
Marc-André Lureau | 6f11081 | 2023-08-30 13:38:23 +0400 | [diff] [blame] | 770 | qemu_text_console_update_cursor(); |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 771 | } |
| 772 | |
Gerd Hoffmann | 0f7b286 | 2013-03-14 11:56:16 +0100 | [diff] [blame] | 773 | void update_displaychangelistener(DisplayChangeListener *dcl, |
| 774 | uint64_t interval) |
| 775 | { |
| 776 | DisplayState *ds = dcl->ds; |
| 777 | |
| 778 | dcl->update_interval = interval; |
| 779 | if (!ds->refreshing && ds->update_interval > interval) { |
Alex Bligh | bc72ad6 | 2013-08-21 16:03:08 +0100 | [diff] [blame] | 780 | timer_mod(ds->gui_timer, ds->last_update + interval); |
Gerd Hoffmann | 0f7b286 | 2013-03-14 11:56:16 +0100 | [diff] [blame] | 781 | } |
| 782 | } |
| 783 | |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 784 | void unregister_displaychangelistener(DisplayChangeListener *dcl) |
| 785 | { |
| 786 | DisplayState *ds = dcl->ds; |
| 787 | trace_displaychangelistener_unregister(dcl, dcl->ops->dpy_name); |
Gerd Hoffmann | 284d1c6 | 2013-03-15 15:45:54 +0100 | [diff] [blame] | 788 | if (dcl->con) { |
| 789 | dcl->con->dcls--; |
| 790 | } |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 791 | QLIST_REMOVE(dcl, next); |
Gerd Hoffmann | 777c5f1 | 2017-11-09 11:51:54 +0100 | [diff] [blame] | 792 | dcl->ds = NULL; |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 793 | gui_setup_refresh(ds); |
| 794 | } |
| 795 | |
Gerd Hoffmann | cf1ecc8 | 2015-03-12 12:51:13 +0100 | [diff] [blame] | 796 | static void dpy_set_ui_info_timer(void *opaque) |
| 797 | { |
| 798 | QemuConsole *con = opaque; |
Marc-André Lureau | 58d5870 | 2023-08-30 13:38:03 +0400 | [diff] [blame] | 799 | uint32_t head = qemu_console_get_head(con); |
Gerd Hoffmann | cf1ecc8 | 2015-03-12 12:51:13 +0100 | [diff] [blame] | 800 | |
Marc-André Lureau | 58d5870 | 2023-08-30 13:38:03 +0400 | [diff] [blame] | 801 | con->hw_ops->ui_info(con->hw, head, &con->ui_info); |
Gerd Hoffmann | cf1ecc8 | 2015-03-12 12:51:13 +0100 | [diff] [blame] | 802 | } |
| 803 | |
Marc-André Lureau | a92e7bb | 2023-09-12 10:13:01 +0400 | [diff] [blame] | 804 | bool dpy_ui_info_supported(const QemuConsole *con) |
Gerd Hoffmann | b7fb49f | 2015-03-13 12:21:14 +0100 | [diff] [blame] | 805 | { |
Gerd Hoffmann | 5c4b107 | 2020-12-08 12:57:30 +0100 | [diff] [blame] | 806 | if (con == NULL) { |
| 807 | con = active_console; |
| 808 | } |
Marc-André Lureau | 48a35e1 | 2023-09-11 18:04:47 +0400 | [diff] [blame] | 809 | if (con == NULL) { |
| 810 | return false; |
| 811 | } |
Gerd Hoffmann | 5c4b107 | 2020-12-08 12:57:30 +0100 | [diff] [blame] | 812 | |
Gerd Hoffmann | b7fb49f | 2015-03-13 12:21:14 +0100 | [diff] [blame] | 813 | return con->hw_ops->ui_info != NULL; |
| 814 | } |
| 815 | |
Marc-André Lureau | 5eaf1e4 | 2020-09-27 18:57:48 +0400 | [diff] [blame] | 816 | const QemuUIInfo *dpy_get_ui_info(const QemuConsole *con) |
| 817 | { |
Marc-André Lureau | a92e7bb | 2023-09-12 10:13:01 +0400 | [diff] [blame] | 818 | assert(dpy_ui_info_supported(con)); |
| 819 | |
Gerd Hoffmann | 5c4b107 | 2020-12-08 12:57:30 +0100 | [diff] [blame] | 820 | if (con == NULL) { |
| 821 | con = active_console; |
| 822 | } |
Marc-André Lureau | 5eaf1e4 | 2020-09-27 18:57:48 +0400 | [diff] [blame] | 823 | |
| 824 | return &con->ui_info; |
| 825 | } |
| 826 | |
Marc-André Lureau | ca19ef5 | 2021-04-13 20:39:11 +0400 | [diff] [blame] | 827 | int dpy_set_ui_info(QemuConsole *con, QemuUIInfo *info, bool delay) |
Gerd Hoffmann | 6f90f3d | 2014-01-24 17:38:20 +0100 | [diff] [blame] | 828 | { |
Gerd Hoffmann | 5c4b107 | 2020-12-08 12:57:30 +0100 | [diff] [blame] | 829 | if (con == NULL) { |
| 830 | con = active_console; |
| 831 | } |
Gerd Hoffmann | 1185fde | 2016-05-30 10:41:13 +0200 | [diff] [blame] | 832 | |
Gerd Hoffmann | b7fb49f | 2015-03-13 12:21:14 +0100 | [diff] [blame] | 833 | if (!dpy_ui_info_supported(con)) { |
Gerd Hoffmann | cf1ecc8 | 2015-03-12 12:51:13 +0100 | [diff] [blame] | 834 | return -1; |
Gerd Hoffmann | 6f90f3d | 2014-01-24 17:38:20 +0100 | [diff] [blame] | 835 | } |
Gerd Hoffmann | 1185fde | 2016-05-30 10:41:13 +0200 | [diff] [blame] | 836 | if (memcmp(&con->ui_info, info, sizeof(con->ui_info)) == 0) { |
| 837 | /* nothing changed -- ignore */ |
| 838 | return 0; |
| 839 | } |
Gerd Hoffmann | cf1ecc8 | 2015-03-12 12:51:13 +0100 | [diff] [blame] | 840 | |
| 841 | /* |
| 842 | * Typically we get a flood of these as the user resizes the window. |
| 843 | * Wait until the dust has settled (one second without updates), then |
| 844 | * go notify the guest. |
| 845 | */ |
Gerd Hoffmann | 1185fde | 2016-05-30 10:41:13 +0200 | [diff] [blame] | 846 | con->ui_info = *info; |
Marc-André Lureau | ca19ef5 | 2021-04-13 20:39:11 +0400 | [diff] [blame] | 847 | timer_mod(con->ui_timer, |
| 848 | qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + (delay ? 1000 : 0)); |
Gerd Hoffmann | cf1ecc8 | 2015-03-12 12:51:13 +0100 | [diff] [blame] | 849 | return 0; |
Gerd Hoffmann | 6f90f3d | 2014-01-24 17:38:20 +0100 | [diff] [blame] | 850 | } |
| 851 | |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 852 | void dpy_gfx_update(QemuConsole *con, int x, int y, int w, int h) |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 853 | { |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 854 | DisplayState *s = con->ds; |
Gerd Hoffmann | 284d1c6 | 2013-03-15 15:45:54 +0100 | [diff] [blame] | 855 | DisplayChangeListener *dcl; |
Marc-André Lureau | ebced09 | 2021-02-20 16:23:03 +0400 | [diff] [blame] | 856 | int width = qemu_console_get_width(con, x + w); |
| 857 | int height = qemu_console_get_height(con, y + h); |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 858 | |
| 859 | x = MAX(x, 0); |
| 860 | y = MAX(y, 0); |
| 861 | x = MIN(x, width); |
| 862 | y = MIN(y, height); |
| 863 | w = MIN(w, width - x); |
| 864 | h = MIN(h, height - y); |
| 865 | |
Gerd Hoffmann | 81c0d5a | 2013-03-14 14:27:08 +0100 | [diff] [blame] | 866 | if (!qemu_console_is_visible(con)) { |
Gerd Hoffmann | 321f048 | 2013-03-12 14:39:22 +0100 | [diff] [blame] | 867 | return; |
| 868 | } |
Marc-André Lureau | 589089f | 2022-02-17 15:07:21 +0400 | [diff] [blame] | 869 | dpy_gfx_update_texture(con, con->surface, x, y, w, h); |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 870 | QLIST_FOREACH(dcl, &s->listeners, next) { |
Gerd Hoffmann | 284d1c6 | 2013-03-15 15:45:54 +0100 | [diff] [blame] | 871 | if (con != (dcl->con ? dcl->con : active_console)) { |
| 872 | continue; |
| 873 | } |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 874 | if (dcl->ops->dpy_gfx_update) { |
Gerd Hoffmann | bc2ed97 | 2013-03-01 13:03:04 +0100 | [diff] [blame] | 875 | dcl->ops->dpy_gfx_update(dcl, x, y, w, h); |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 876 | } |
| 877 | } |
| 878 | } |
| 879 | |
Tina Zhang | 7cd0afe | 2018-04-27 17:11:05 +0800 | [diff] [blame] | 880 | void dpy_gfx_update_full(QemuConsole *con) |
| 881 | { |
Marc-André Lureau | ebced09 | 2021-02-20 16:23:03 +0400 | [diff] [blame] | 882 | int w = qemu_console_get_width(con, 0); |
| 883 | int h = qemu_console_get_height(con, 0); |
| 884 | |
| 885 | dpy_gfx_update(con, 0, 0, w, h); |
Tina Zhang | 7cd0afe | 2018-04-27 17:11:05 +0800 | [diff] [blame] | 886 | } |
| 887 | |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 888 | void dpy_gfx_replace_surface(QemuConsole *con, |
Gerd Hoffmann | da229ef | 2013-02-28 10:48:02 +0100 | [diff] [blame] | 889 | DisplaySurface *surface) |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 890 | { |
Akihiko Odaki | c821a58 | 2021-02-25 19:13:15 +0900 | [diff] [blame] | 891 | static const char placeholder_msg[] = "Display output is not active."; |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 892 | DisplayState *s = con->ds; |
Gerd Hoffmann | 321f048 | 2013-03-12 14:39:22 +0100 | [diff] [blame] | 893 | DisplaySurface *old_surface = con->surface; |
Dongwon Kim | 0d0be87 | 2023-06-27 15:44:51 -0700 | [diff] [blame] | 894 | DisplaySurface *new_surface = surface; |
Gerd Hoffmann | 284d1c6 | 2013-03-15 15:45:54 +0100 | [diff] [blame] | 895 | DisplayChangeListener *dcl; |
Akihiko Odaki | c821a58 | 2021-02-25 19:13:15 +0900 | [diff] [blame] | 896 | int width; |
| 897 | int height; |
Gerd Hoffmann | da229ef | 2013-02-28 10:48:02 +0100 | [diff] [blame] | 898 | |
Akihiko Odaki | c821a58 | 2021-02-25 19:13:15 +0900 | [diff] [blame] | 899 | if (!surface) { |
| 900 | if (old_surface) { |
| 901 | width = surface_width(old_surface); |
| 902 | height = surface_height(old_surface); |
| 903 | } else { |
| 904 | width = 640; |
| 905 | height = 480; |
| 906 | } |
| 907 | |
Dongwon Kim | 0d0be87 | 2023-06-27 15:44:51 -0700 | [diff] [blame] | 908 | new_surface = qemu_create_placeholder_surface(width, height, placeholder_msg); |
Akihiko Odaki | c821a58 | 2021-02-25 19:13:15 +0900 | [diff] [blame] | 909 | } |
| 910 | |
Dongwon Kim | 0d0be87 | 2023-06-27 15:44:51 -0700 | [diff] [blame] | 911 | assert(old_surface != new_surface); |
Marc-André Lureau | 6905b93 | 2017-04-06 14:05:11 +0200 | [diff] [blame] | 912 | |
Marc-André Lureau | ebced09 | 2021-02-20 16:23:03 +0400 | [diff] [blame] | 913 | con->scanout.kind = SCANOUT_SURFACE; |
Dongwon Kim | 0d0be87 | 2023-06-27 15:44:51 -0700 | [diff] [blame] | 914 | con->surface = new_surface; |
| 915 | dpy_gfx_create_texture(con, new_surface); |
Gerd Hoffmann | 284d1c6 | 2013-03-15 15:45:54 +0100 | [diff] [blame] | 916 | QLIST_FOREACH(dcl, &s->listeners, next) { |
| 917 | if (con != (dcl->con ? dcl->con : active_console)) { |
| 918 | continue; |
| 919 | } |
Dongwon Kim | 0d0be87 | 2023-06-27 15:44:51 -0700 | [diff] [blame] | 920 | displaychangelistener_gfx_switch(dcl, new_surface, surface ? FALSE : TRUE); |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 921 | } |
Marc-André Lureau | 589089f | 2022-02-17 15:07:21 +0400 | [diff] [blame] | 922 | dpy_gfx_destroy_texture(con, old_surface); |
Gerd Hoffmann | da229ef | 2013-02-28 10:48:02 +0100 | [diff] [blame] | 923 | qemu_free_displaysurface(old_surface); |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 924 | } |
| 925 | |
Benjamin Herrenschmidt | 49743df | 2014-07-07 16:39:05 +1000 | [diff] [blame] | 926 | bool dpy_gfx_check_format(QemuConsole *con, |
| 927 | pixman_format_code_t format) |
| 928 | { |
| 929 | DisplayChangeListener *dcl; |
| 930 | DisplayState *s = con->ds; |
| 931 | |
| 932 | QLIST_FOREACH(dcl, &s->listeners, next) { |
| 933 | if (dcl->con && dcl->con != con) { |
| 934 | /* dcl bound to another console -> skip */ |
| 935 | continue; |
| 936 | } |
| 937 | if (dcl->ops->dpy_gfx_check_format) { |
| 938 | if (!dcl->ops->dpy_gfx_check_format(dcl, format)) { |
| 939 | return false; |
| 940 | } |
| 941 | } else { |
Philippe Mathieu-Daudé | 75ae7c4 | 2021-03-03 19:46:40 +0100 | [diff] [blame] | 942 | /* default is to allow native 32 bpp only */ |
Benjamin Herrenschmidt | 49743df | 2014-07-07 16:39:05 +1000 | [diff] [blame] | 943 | if (format != qemu_default_pixman_format(32, true)) { |
| 944 | return false; |
| 945 | } |
| 946 | } |
| 947 | } |
| 948 | return true; |
| 949 | } |
| 950 | |
Stefan Weil | 6075137 | 2014-05-02 22:48:30 +0200 | [diff] [blame] | 951 | static void dpy_refresh(DisplayState *s) |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 952 | { |
Gerd Hoffmann | 284d1c6 | 2013-03-15 15:45:54 +0100 | [diff] [blame] | 953 | DisplayChangeListener *dcl; |
| 954 | |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 955 | QLIST_FOREACH(dcl, &s->listeners, next) { |
| 956 | if (dcl->ops->dpy_refresh) { |
Gerd Hoffmann | 3f8f131 | 2017-06-14 10:45:38 +0200 | [diff] [blame] | 957 | dcl->ops->dpy_refresh(dcl); |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 958 | } |
| 959 | } |
| 960 | } |
| 961 | |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 962 | void dpy_text_cursor(QemuConsole *con, int x, int y) |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 963 | { |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 964 | DisplayState *s = con->ds; |
Gerd Hoffmann | 284d1c6 | 2013-03-15 15:45:54 +0100 | [diff] [blame] | 965 | DisplayChangeListener *dcl; |
Gerd Hoffmann | 321f048 | 2013-03-12 14:39:22 +0100 | [diff] [blame] | 966 | |
Gerd Hoffmann | 81c0d5a | 2013-03-14 14:27:08 +0100 | [diff] [blame] | 967 | if (!qemu_console_is_visible(con)) { |
Gerd Hoffmann | 321f048 | 2013-03-12 14:39:22 +0100 | [diff] [blame] | 968 | return; |
| 969 | } |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 970 | QLIST_FOREACH(dcl, &s->listeners, next) { |
Gerd Hoffmann | 284d1c6 | 2013-03-15 15:45:54 +0100 | [diff] [blame] | 971 | if (con != (dcl->con ? dcl->con : active_console)) { |
| 972 | continue; |
| 973 | } |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 974 | if (dcl->ops->dpy_text_cursor) { |
Gerd Hoffmann | bc2ed97 | 2013-03-01 13:03:04 +0100 | [diff] [blame] | 975 | dcl->ops->dpy_text_cursor(dcl, x, y); |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 976 | } |
| 977 | } |
| 978 | } |
| 979 | |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 980 | void dpy_text_update(QemuConsole *con, int x, int y, int w, int h) |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 981 | { |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 982 | DisplayState *s = con->ds; |
Gerd Hoffmann | 284d1c6 | 2013-03-15 15:45:54 +0100 | [diff] [blame] | 983 | DisplayChangeListener *dcl; |
Gerd Hoffmann | 321f048 | 2013-03-12 14:39:22 +0100 | [diff] [blame] | 984 | |
Gerd Hoffmann | 81c0d5a | 2013-03-14 14:27:08 +0100 | [diff] [blame] | 985 | if (!qemu_console_is_visible(con)) { |
Gerd Hoffmann | 321f048 | 2013-03-12 14:39:22 +0100 | [diff] [blame] | 986 | return; |
| 987 | } |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 988 | QLIST_FOREACH(dcl, &s->listeners, next) { |
Gerd Hoffmann | 284d1c6 | 2013-03-15 15:45:54 +0100 | [diff] [blame] | 989 | if (con != (dcl->con ? dcl->con : active_console)) { |
| 990 | continue; |
| 991 | } |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 992 | if (dcl->ops->dpy_text_update) { |
Gerd Hoffmann | bc2ed97 | 2013-03-01 13:03:04 +0100 | [diff] [blame] | 993 | dcl->ops->dpy_text_update(dcl, x, y, w, h); |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 994 | } |
| 995 | } |
| 996 | } |
| 997 | |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 998 | void dpy_text_resize(QemuConsole *con, int w, int h) |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 999 | { |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 1000 | DisplayState *s = con->ds; |
Chih-Min Chao | 9425c00 | 2015-04-09 02:04:13 +0800 | [diff] [blame] | 1001 | DisplayChangeListener *dcl; |
Gerd Hoffmann | 321f048 | 2013-03-12 14:39:22 +0100 | [diff] [blame] | 1002 | |
Gerd Hoffmann | 81c0d5a | 2013-03-14 14:27:08 +0100 | [diff] [blame] | 1003 | if (!qemu_console_is_visible(con)) { |
Gerd Hoffmann | 321f048 | 2013-03-12 14:39:22 +0100 | [diff] [blame] | 1004 | return; |
| 1005 | } |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 1006 | QLIST_FOREACH(dcl, &s->listeners, next) { |
Gerd Hoffmann | 284d1c6 | 2013-03-15 15:45:54 +0100 | [diff] [blame] | 1007 | if (con != (dcl->con ? dcl->con : active_console)) { |
| 1008 | continue; |
| 1009 | } |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 1010 | if (dcl->ops->dpy_text_resize) { |
Gerd Hoffmann | bc2ed97 | 2013-03-01 13:03:04 +0100 | [diff] [blame] | 1011 | dcl->ops->dpy_text_resize(dcl, w, h); |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 1012 | } |
| 1013 | } |
| 1014 | } |
| 1015 | |
Marc-André Lureau | 58d5870 | 2023-08-30 13:38:03 +0400 | [diff] [blame] | 1016 | void dpy_mouse_set(QemuConsole *c, int x, int y, int on) |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 1017 | { |
Marc-André Lureau | 58d5870 | 2023-08-30 13:38:03 +0400 | [diff] [blame] | 1018 | QemuGraphicConsole *con = QEMU_GRAPHIC_CONSOLE(c); |
| 1019 | DisplayState *s = c->ds; |
Gerd Hoffmann | 284d1c6 | 2013-03-15 15:45:54 +0100 | [diff] [blame] | 1020 | DisplayChangeListener *dcl; |
Gerd Hoffmann | 321f048 | 2013-03-12 14:39:22 +0100 | [diff] [blame] | 1021 | |
Marc-André Lureau | 6effaa1 | 2023-01-17 15:40:58 +0400 | [diff] [blame] | 1022 | con->cursor_x = x; |
| 1023 | con->cursor_y = y; |
| 1024 | con->cursor_on = on; |
Marc-André Lureau | 58d5870 | 2023-08-30 13:38:03 +0400 | [diff] [blame] | 1025 | if (!qemu_console_is_visible(c)) { |
Gerd Hoffmann | 321f048 | 2013-03-12 14:39:22 +0100 | [diff] [blame] | 1026 | return; |
| 1027 | } |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 1028 | QLIST_FOREACH(dcl, &s->listeners, next) { |
Marc-André Lureau | 58d5870 | 2023-08-30 13:38:03 +0400 | [diff] [blame] | 1029 | if (c != (dcl->con ? dcl->con : active_console)) { |
Gerd Hoffmann | 284d1c6 | 2013-03-15 15:45:54 +0100 | [diff] [blame] | 1030 | continue; |
| 1031 | } |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 1032 | if (dcl->ops->dpy_mouse_set) { |
Gerd Hoffmann | bc2ed97 | 2013-03-01 13:03:04 +0100 | [diff] [blame] | 1033 | dcl->ops->dpy_mouse_set(dcl, x, y, on); |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 1034 | } |
| 1035 | } |
| 1036 | } |
| 1037 | |
Marc-André Lureau | 58d5870 | 2023-08-30 13:38:03 +0400 | [diff] [blame] | 1038 | void dpy_cursor_define(QemuConsole *c, QEMUCursor *cursor) |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 1039 | { |
Marc-André Lureau | 58d5870 | 2023-08-30 13:38:03 +0400 | [diff] [blame] | 1040 | QemuGraphicConsole *con = QEMU_GRAPHIC_CONSOLE(c); |
| 1041 | DisplayState *s = c->ds; |
Gerd Hoffmann | 284d1c6 | 2013-03-15 15:45:54 +0100 | [diff] [blame] | 1042 | DisplayChangeListener *dcl; |
Gerd Hoffmann | 321f048 | 2013-03-12 14:39:22 +0100 | [diff] [blame] | 1043 | |
Marc-André Lureau | 385ac97 | 2023-01-17 15:24:40 +0400 | [diff] [blame] | 1044 | cursor_unref(con->cursor); |
| 1045 | con->cursor = cursor_ref(cursor); |
Marc-André Lureau | 58d5870 | 2023-08-30 13:38:03 +0400 | [diff] [blame] | 1046 | if (!qemu_console_is_visible(c)) { |
Gerd Hoffmann | 321f048 | 2013-03-12 14:39:22 +0100 | [diff] [blame] | 1047 | return; |
| 1048 | } |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 1049 | QLIST_FOREACH(dcl, &s->listeners, next) { |
Marc-André Lureau | 58d5870 | 2023-08-30 13:38:03 +0400 | [diff] [blame] | 1050 | if (c != (dcl->con ? dcl->con : active_console)) { |
Gerd Hoffmann | 284d1c6 | 2013-03-15 15:45:54 +0100 | [diff] [blame] | 1051 | continue; |
| 1052 | } |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 1053 | if (dcl->ops->dpy_cursor_define) { |
Gerd Hoffmann | bc2ed97 | 2013-03-01 13:03:04 +0100 | [diff] [blame] | 1054 | dcl->ops->dpy_cursor_define(dcl, cursor); |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 1055 | } |
| 1056 | } |
| 1057 | } |
| 1058 | |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 1059 | bool dpy_cursor_define_supported(QemuConsole *con) |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 1060 | { |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 1061 | DisplayState *s = con->ds; |
Gerd Hoffmann | 284d1c6 | 2013-03-15 15:45:54 +0100 | [diff] [blame] | 1062 | DisplayChangeListener *dcl; |
| 1063 | |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 1064 | QLIST_FOREACH(dcl, &s->listeners, next) { |
| 1065 | if (dcl->ops->dpy_cursor_define) { |
| 1066 | return true; |
| 1067 | } |
| 1068 | } |
| 1069 | return false; |
| 1070 | } |
| 1071 | |
Gerd Hoffmann | 06020b9 | 2014-07-11 13:56:51 +0200 | [diff] [blame] | 1072 | QEMUGLContext dpy_gl_ctx_create(QemuConsole *con, |
| 1073 | struct QEMUGLParams *qparams) |
| 1074 | { |
| 1075 | assert(con->gl); |
| 1076 | return con->gl->ops->dpy_gl_ctx_create(con->gl, qparams); |
| 1077 | } |
| 1078 | |
| 1079 | void dpy_gl_ctx_destroy(QemuConsole *con, QEMUGLContext ctx) |
| 1080 | { |
| 1081 | assert(con->gl); |
| 1082 | con->gl->ops->dpy_gl_ctx_destroy(con->gl, ctx); |
| 1083 | } |
| 1084 | |
| 1085 | int dpy_gl_ctx_make_current(QemuConsole *con, QEMUGLContext ctx) |
| 1086 | { |
| 1087 | assert(con->gl); |
| 1088 | return con->gl->ops->dpy_gl_ctx_make_current(con->gl, ctx); |
| 1089 | } |
| 1090 | |
Gerd Hoffmann | eaa92c7 | 2017-02-21 10:37:17 +0100 | [diff] [blame] | 1091 | void dpy_gl_scanout_disable(QemuConsole *con) |
| 1092 | { |
Marc-André Lureau | 7cc712e | 2021-01-26 00:00:30 +0400 | [diff] [blame] | 1093 | DisplayState *s = con->ds; |
| 1094 | DisplayChangeListener *dcl; |
| 1095 | |
Marc-André Lureau | ebced09 | 2021-02-20 16:23:03 +0400 | [diff] [blame] | 1096 | if (con->scanout.kind != SCANOUT_SURFACE) { |
| 1097 | con->scanout.kind = SCANOUT_NONE; |
| 1098 | } |
Marc-André Lureau | 7cc712e | 2021-01-26 00:00:30 +0400 | [diff] [blame] | 1099 | QLIST_FOREACH(dcl, &s->listeners, next) { |
Akihiko Odaki | 1699d00 | 2022-03-26 01:12:16 +0900 | [diff] [blame] | 1100 | if (con != (dcl->con ? dcl->con : active_console)) { |
| 1101 | continue; |
| 1102 | } |
Marc-André Lureau | a9fbce5 | 2022-02-15 00:13:35 +0400 | [diff] [blame] | 1103 | if (dcl->ops->dpy_gl_scanout_disable) { |
| 1104 | dcl->ops->dpy_gl_scanout_disable(dcl); |
| 1105 | } |
Marc-André Lureau | 7cc712e | 2021-01-26 00:00:30 +0400 | [diff] [blame] | 1106 | } |
Gerd Hoffmann | eaa92c7 | 2017-02-21 10:37:17 +0100 | [diff] [blame] | 1107 | } |
| 1108 | |
Gerd Hoffmann | f4c36bd | 2017-02-21 10:37:16 +0100 | [diff] [blame] | 1109 | void dpy_gl_scanout_texture(QemuConsole *con, |
| 1110 | uint32_t backing_id, |
| 1111 | bool backing_y_0_top, |
| 1112 | uint32_t backing_width, |
| 1113 | uint32_t backing_height, |
| 1114 | uint32_t x, uint32_t y, |
Marc-André Lureau | bf41ab6 | 2023-06-06 15:56:56 +0400 | [diff] [blame] | 1115 | uint32_t width, uint32_t height, |
| 1116 | void *d3d_tex2d) |
Gerd Hoffmann | 06020b9 | 2014-07-11 13:56:51 +0200 | [diff] [blame] | 1117 | { |
Marc-André Lureau | 7cc712e | 2021-01-26 00:00:30 +0400 | [diff] [blame] | 1118 | DisplayState *s = con->ds; |
| 1119 | DisplayChangeListener *dcl; |
| 1120 | |
Marc-André Lureau | ebced09 | 2021-02-20 16:23:03 +0400 | [diff] [blame] | 1121 | con->scanout.kind = SCANOUT_TEXTURE; |
| 1122 | con->scanout.texture = (ScanoutTexture) { |
| 1123 | backing_id, backing_y_0_top, backing_width, backing_height, |
Marc-André Lureau | bf41ab6 | 2023-06-06 15:56:56 +0400 | [diff] [blame] | 1124 | x, y, width, height, d3d_tex2d, |
Marc-André Lureau | ebced09 | 2021-02-20 16:23:03 +0400 | [diff] [blame] | 1125 | }; |
Marc-André Lureau | 7cc712e | 2021-01-26 00:00:30 +0400 | [diff] [blame] | 1126 | QLIST_FOREACH(dcl, &s->listeners, next) { |
Akihiko Odaki | 1699d00 | 2022-03-26 01:12:16 +0900 | [diff] [blame] | 1127 | if (con != (dcl->con ? dcl->con : active_console)) { |
| 1128 | continue; |
| 1129 | } |
Marc-André Lureau | a9fbce5 | 2022-02-15 00:13:35 +0400 | [diff] [blame] | 1130 | if (dcl->ops->dpy_gl_scanout_texture) { |
| 1131 | dcl->ops->dpy_gl_scanout_texture(dcl, backing_id, |
| 1132 | backing_y_0_top, |
| 1133 | backing_width, backing_height, |
Marc-André Lureau | bf41ab6 | 2023-06-06 15:56:56 +0400 | [diff] [blame] | 1134 | x, y, width, height, |
| 1135 | d3d_tex2d); |
Marc-André Lureau | a9fbce5 | 2022-02-15 00:13:35 +0400 | [diff] [blame] | 1136 | } |
Marc-André Lureau | 7cc712e | 2021-01-26 00:00:30 +0400 | [diff] [blame] | 1137 | } |
Gerd Hoffmann | 06020b9 | 2014-07-11 13:56:51 +0200 | [diff] [blame] | 1138 | } |
| 1139 | |
Gerd Hoffmann | 4133fa7 | 2017-10-10 15:54:48 +0200 | [diff] [blame] | 1140 | void dpy_gl_scanout_dmabuf(QemuConsole *con, |
| 1141 | QemuDmaBuf *dmabuf) |
| 1142 | { |
Marc-André Lureau | 7cc712e | 2021-01-26 00:00:30 +0400 | [diff] [blame] | 1143 | DisplayState *s = con->ds; |
| 1144 | DisplayChangeListener *dcl; |
| 1145 | |
Marc-André Lureau | ebced09 | 2021-02-20 16:23:03 +0400 | [diff] [blame] | 1146 | con->scanout.kind = SCANOUT_DMABUF; |
| 1147 | con->scanout.dmabuf = dmabuf; |
Marc-André Lureau | 7cc712e | 2021-01-26 00:00:30 +0400 | [diff] [blame] | 1148 | QLIST_FOREACH(dcl, &s->listeners, next) { |
Akihiko Odaki | 1699d00 | 2022-03-26 01:12:16 +0900 | [diff] [blame] | 1149 | if (con != (dcl->con ? dcl->con : active_console)) { |
| 1150 | continue; |
| 1151 | } |
Marc-André Lureau | a9fbce5 | 2022-02-15 00:13:35 +0400 | [diff] [blame] | 1152 | if (dcl->ops->dpy_gl_scanout_dmabuf) { |
| 1153 | dcl->ops->dpy_gl_scanout_dmabuf(dcl, dmabuf); |
| 1154 | } |
Marc-André Lureau | 7cc712e | 2021-01-26 00:00:30 +0400 | [diff] [blame] | 1155 | } |
Gerd Hoffmann | 4133fa7 | 2017-10-10 15:54:48 +0200 | [diff] [blame] | 1156 | } |
| 1157 | |
Gerd Hoffmann | 6e1f2cb | 2018-02-20 12:04:31 +0100 | [diff] [blame] | 1158 | void dpy_gl_cursor_dmabuf(QemuConsole *con, QemuDmaBuf *dmabuf, |
| 1159 | bool have_hot, uint32_t hot_x, uint32_t hot_y) |
Gerd Hoffmann | 4133fa7 | 2017-10-10 15:54:48 +0200 | [diff] [blame] | 1160 | { |
Marc-André Lureau | 7cc712e | 2021-01-26 00:00:30 +0400 | [diff] [blame] | 1161 | DisplayState *s = con->ds; |
| 1162 | DisplayChangeListener *dcl; |
Gerd Hoffmann | 4133fa7 | 2017-10-10 15:54:48 +0200 | [diff] [blame] | 1163 | |
Marc-André Lureau | 7cc712e | 2021-01-26 00:00:30 +0400 | [diff] [blame] | 1164 | QLIST_FOREACH(dcl, &s->listeners, next) { |
Akihiko Odaki | 1699d00 | 2022-03-26 01:12:16 +0900 | [diff] [blame] | 1165 | if (con != (dcl->con ? dcl->con : active_console)) { |
| 1166 | continue; |
| 1167 | } |
Marc-André Lureau | 7cc712e | 2021-01-26 00:00:30 +0400 | [diff] [blame] | 1168 | if (dcl->ops->dpy_gl_cursor_dmabuf) { |
| 1169 | dcl->ops->dpy_gl_cursor_dmabuf(dcl, dmabuf, |
Gerd Hoffmann | 6e1f2cb | 2018-02-20 12:04:31 +0100 | [diff] [blame] | 1170 | have_hot, hot_x, hot_y); |
Marc-André Lureau | 7cc712e | 2021-01-26 00:00:30 +0400 | [diff] [blame] | 1171 | } |
Gerd Hoffmann | 6e1f2cb | 2018-02-20 12:04:31 +0100 | [diff] [blame] | 1172 | } |
| 1173 | } |
| 1174 | |
| 1175 | void dpy_gl_cursor_position(QemuConsole *con, |
| 1176 | uint32_t pos_x, uint32_t pos_y) |
| 1177 | { |
Marc-André Lureau | 7cc712e | 2021-01-26 00:00:30 +0400 | [diff] [blame] | 1178 | DisplayState *s = con->ds; |
| 1179 | DisplayChangeListener *dcl; |
Gerd Hoffmann | 6e1f2cb | 2018-02-20 12:04:31 +0100 | [diff] [blame] | 1180 | |
Marc-André Lureau | 7cc712e | 2021-01-26 00:00:30 +0400 | [diff] [blame] | 1181 | QLIST_FOREACH(dcl, &s->listeners, next) { |
Akihiko Odaki | 1699d00 | 2022-03-26 01:12:16 +0900 | [diff] [blame] | 1182 | if (con != (dcl->con ? dcl->con : active_console)) { |
| 1183 | continue; |
| 1184 | } |
Marc-André Lureau | 7cc712e | 2021-01-26 00:00:30 +0400 | [diff] [blame] | 1185 | if (dcl->ops->dpy_gl_cursor_position) { |
| 1186 | dcl->ops->dpy_gl_cursor_position(dcl, pos_x, pos_y); |
| 1187 | } |
Gerd Hoffmann | 4133fa7 | 2017-10-10 15:54:48 +0200 | [diff] [blame] | 1188 | } |
| 1189 | } |
| 1190 | |
| 1191 | void dpy_gl_release_dmabuf(QemuConsole *con, |
| 1192 | QemuDmaBuf *dmabuf) |
| 1193 | { |
Marc-André Lureau | 7cc712e | 2021-01-26 00:00:30 +0400 | [diff] [blame] | 1194 | DisplayState *s = con->ds; |
| 1195 | DisplayChangeListener *dcl; |
Gerd Hoffmann | 4133fa7 | 2017-10-10 15:54:48 +0200 | [diff] [blame] | 1196 | |
Marc-André Lureau | 7cc712e | 2021-01-26 00:00:30 +0400 | [diff] [blame] | 1197 | QLIST_FOREACH(dcl, &s->listeners, next) { |
Akihiko Odaki | 1699d00 | 2022-03-26 01:12:16 +0900 | [diff] [blame] | 1198 | if (con != (dcl->con ? dcl->con : active_console)) { |
| 1199 | continue; |
| 1200 | } |
Marc-André Lureau | 7cc712e | 2021-01-26 00:00:30 +0400 | [diff] [blame] | 1201 | if (dcl->ops->dpy_gl_release_dmabuf) { |
| 1202 | dcl->ops->dpy_gl_release_dmabuf(dcl, dmabuf); |
| 1203 | } |
Gerd Hoffmann | 4133fa7 | 2017-10-10 15:54:48 +0200 | [diff] [blame] | 1204 | } |
| 1205 | } |
| 1206 | |
Gerd Hoffmann | 06020b9 | 2014-07-11 13:56:51 +0200 | [diff] [blame] | 1207 | void dpy_gl_update(QemuConsole *con, |
| 1208 | uint32_t x, uint32_t y, uint32_t w, uint32_t h) |
| 1209 | { |
Marc-André Lureau | 7cc712e | 2021-01-26 00:00:30 +0400 | [diff] [blame] | 1210 | DisplayState *s = con->ds; |
| 1211 | DisplayChangeListener *dcl; |
| 1212 | |
Gerd Hoffmann | 06020b9 | 2014-07-11 13:56:51 +0200 | [diff] [blame] | 1213 | assert(con->gl); |
Marc-André Lureau | f6413cb | 2021-03-11 12:11:37 +0400 | [diff] [blame] | 1214 | |
| 1215 | graphic_hw_gl_block(con, true); |
Marc-André Lureau | 7cc712e | 2021-01-26 00:00:30 +0400 | [diff] [blame] | 1216 | QLIST_FOREACH(dcl, &s->listeners, next) { |
Akihiko Odaki | 1699d00 | 2022-03-26 01:12:16 +0900 | [diff] [blame] | 1217 | if (con != (dcl->con ? dcl->con : active_console)) { |
| 1218 | continue; |
| 1219 | } |
Marc-André Lureau | a9fbce5 | 2022-02-15 00:13:35 +0400 | [diff] [blame] | 1220 | if (dcl->ops->dpy_gl_update) { |
| 1221 | dcl->ops->dpy_gl_update(dcl, x, y, w, h); |
| 1222 | } |
Marc-André Lureau | 7cc712e | 2021-01-26 00:00:30 +0400 | [diff] [blame] | 1223 | } |
Marc-André Lureau | f6413cb | 2021-03-11 12:11:37 +0400 | [diff] [blame] | 1224 | graphic_hw_gl_block(con, false); |
Gerd Hoffmann | 06020b9 | 2014-07-11 13:56:51 +0200 | [diff] [blame] | 1225 | } |
| 1226 | |
Paolo Bonzini | 98b5008 | 2010-02-11 00:29:57 +0100 | [diff] [blame] | 1227 | /***********************************************************/ |
| 1228 | /* register display */ |
| 1229 | |
Gerd Hoffmann | 64840c6 | 2013-03-07 17:08:29 +0100 | [diff] [blame] | 1230 | /* console.c internal use only */ |
| 1231 | static DisplayState *get_alloc_displaystate(void) |
Paolo Bonzini | 98b5008 | 2010-02-11 00:29:57 +0100 | [diff] [blame] | 1232 | { |
| 1233 | if (!display_state) { |
Gerd Hoffmann | 64840c6 | 2013-03-07 17:08:29 +0100 | [diff] [blame] | 1234 | display_state = g_new0(DisplayState, 1); |
Paolo Bonzini | 98b5008 | 2010-02-11 00:29:57 +0100 | [diff] [blame] | 1235 | } |
| 1236 | return display_state; |
| 1237 | } |
| 1238 | |
Gerd Hoffmann | 64840c6 | 2013-03-07 17:08:29 +0100 | [diff] [blame] | 1239 | /* |
| 1240 | * Called by main(), after creating QemuConsoles |
| 1241 | * and before initializing ui (sdl/vnc/...). |
| 1242 | */ |
| 1243 | DisplayState *init_displaystate(void) |
| 1244 | { |
Gerd Hoffmann | 43f420f | 2013-06-25 10:49:31 +0200 | [diff] [blame] | 1245 | gchar *name; |
Gerd Hoffmann | cd6cd8f | 2018-05-07 11:54:24 +0200 | [diff] [blame] | 1246 | QemuConsole *con; |
Gerd Hoffmann | 64840c6 | 2013-03-07 17:08:29 +0100 | [diff] [blame] | 1247 | |
Gerd Hoffmann | cd6cd8f | 2018-05-07 11:54:24 +0200 | [diff] [blame] | 1248 | QTAILQ_FOREACH(con, &consoles, next) { |
Marc-André Lureau | 34b7751 | 2023-08-30 13:37:56 +0400 | [diff] [blame] | 1249 | /* Hook up into the qom tree here (not in object_new()), once |
Gerd Hoffmann | 43f420f | 2013-06-25 10:49:31 +0200 | [diff] [blame] | 1250 | * all QemuConsoles are created and the order / numbering |
| 1251 | * doesn't change any more */ |
Gerd Hoffmann | cd6cd8f | 2018-05-07 11:54:24 +0200 | [diff] [blame] | 1252 | name = g_strdup_printf("console[%d]", con->index); |
Gerd Hoffmann | 43f420f | 2013-06-25 10:49:31 +0200 | [diff] [blame] | 1253 | object_property_add_child(container_get(object_get_root(), "/backend"), |
Markus Armbruster | d262312 | 2020-05-05 17:29:22 +0200 | [diff] [blame] | 1254 | name, OBJECT(con)); |
Gerd Hoffmann | 43f420f | 2013-06-25 10:49:31 +0200 | [diff] [blame] | 1255 | g_free(name); |
Gerd Hoffmann | 64840c6 | 2013-03-07 17:08:29 +0100 | [diff] [blame] | 1256 | } |
| 1257 | |
| 1258 | return display_state; |
| 1259 | } |
| 1260 | |
Gerd Hoffmann | 1c1f949 | 2014-09-24 17:05:27 +0200 | [diff] [blame] | 1261 | void graphic_console_set_hwops(QemuConsole *con, |
| 1262 | const GraphicHwOps *hw_ops, |
| 1263 | void *opaque) |
| 1264 | { |
| 1265 | con->hw_ops = hw_ops; |
| 1266 | con->hw = opaque; |
| 1267 | } |
| 1268 | |
Gerd Hoffmann | 5643706 | 2014-01-24 15:35:21 +0100 | [diff] [blame] | 1269 | QemuConsole *graphic_console_init(DeviceState *dev, uint32_t head, |
Gerd Hoffmann | aa2beaa | 2013-04-17 10:21:27 +0200 | [diff] [blame] | 1270 | const GraphicHwOps *hw_ops, |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 1271 | void *opaque) |
bellard | e7f0ad5 | 2004-07-14 17:28:59 +0000 | [diff] [blame] | 1272 | { |
Gerd Hoffmann | 521a580 | 2013-04-25 12:10:45 +0200 | [diff] [blame] | 1273 | static const char noinit[] = |
| 1274 | "Guest has not initialized the display (yet)."; |
Gerd Hoffmann | 64840c6 | 2013-03-07 17:08:29 +0100 | [diff] [blame] | 1275 | int width = 640; |
| 1276 | int height = 480; |
Gerd Hoffmann | 76ffb0b | 2012-09-28 13:24:17 +0200 | [diff] [blame] | 1277 | QemuConsole *s; |
Gerd Hoffmann | 9588d67 | 2018-03-13 11:17:29 -0600 | [diff] [blame] | 1278 | DisplaySurface *surface; |
aurel32 | f0f2f97 | 2009-01-16 21:13:49 +0000 | [diff] [blame] | 1279 | |
Marc-André Lureau | f9411aa | 2023-08-30 13:37:57 +0400 | [diff] [blame] | 1280 | s = qemu_graphic_console_lookup_unused(); |
Gerd Hoffmann | 9588d67 | 2018-03-13 11:17:29 -0600 | [diff] [blame] | 1281 | if (s) { |
| 1282 | trace_console_gfx_reuse(s->index); |
Marc-André Lureau | ebced09 | 2021-02-20 16:23:03 +0400 | [diff] [blame] | 1283 | width = qemu_console_get_width(s, 0); |
| 1284 | height = qemu_console_get_height(s, 0); |
Gerd Hoffmann | 9588d67 | 2018-03-13 11:17:29 -0600 | [diff] [blame] | 1285 | } else { |
| 1286 | trace_console_gfx_new(); |
Marc-André Lureau | 34b7751 | 2023-08-30 13:37:56 +0400 | [diff] [blame] | 1287 | s = (QemuConsole *)object_new(TYPE_QEMU_GRAPHIC_CONSOLE); |
Gerd Hoffmann | 9588d67 | 2018-03-13 11:17:29 -0600 | [diff] [blame] | 1288 | } |
Marc-André Lureau | 58d5870 | 2023-08-30 13:38:03 +0400 | [diff] [blame] | 1289 | QEMU_GRAPHIC_CONSOLE(s)->head = head; |
Gerd Hoffmann | 1c1f949 | 2014-09-24 17:05:27 +0200 | [diff] [blame] | 1290 | graphic_console_set_hwops(s, hw_ops, opaque); |
Gerd Hoffmann | aa2beaa | 2013-04-17 10:21:27 +0200 | [diff] [blame] | 1291 | if (dev) { |
Markus Armbruster | 5325cc3 | 2020-07-07 18:05:54 +0200 | [diff] [blame] | 1292 | object_property_set_link(OBJECT(s), "device", OBJECT(dev), |
Kirill Batuzov | afff2b1 | 2014-04-24 18:15:58 +0400 | [diff] [blame] | 1293 | &error_abort); |
Gerd Hoffmann | aa2beaa | 2013-04-17 10:21:27 +0200 | [diff] [blame] | 1294 | } |
aliguori | 3023f33 | 2009-01-16 19:04:14 +0000 | [diff] [blame] | 1295 | |
Akihiko Odaki | b5a087b | 2021-02-25 19:13:14 +0900 | [diff] [blame] | 1296 | surface = qemu_create_placeholder_surface(width, height, noinit); |
Gerd Hoffmann | 9588d67 | 2018-03-13 11:17:29 -0600 | [diff] [blame] | 1297 | dpy_gfx_replace_surface(s, surface); |
Marc-André Lureau | a9b1e47 | 2021-03-11 11:56:58 +0400 | [diff] [blame] | 1298 | s->gl_unblock_timer = timer_new_ms(QEMU_CLOCK_REALTIME, |
| 1299 | graphic_hw_gl_unblock_timer, s); |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 1300 | return s; |
pbrook | 9521989 | 2006-04-09 01:06:34 +0000 | [diff] [blame] | 1301 | } |
| 1302 | |
Gerd Hoffmann | 9588d67 | 2018-03-13 11:17:29 -0600 | [diff] [blame] | 1303 | static const GraphicHwOps unused_ops = { |
| 1304 | /* no callbacks */ |
| 1305 | }; |
| 1306 | |
| 1307 | void graphic_console_close(QemuConsole *con) |
| 1308 | { |
| 1309 | static const char unplugged[] = |
| 1310 | "Guest display has been unplugged"; |
| 1311 | DisplaySurface *surface; |
Marc-André Lureau | ebced09 | 2021-02-20 16:23:03 +0400 | [diff] [blame] | 1312 | int width = qemu_console_get_width(con, 640); |
| 1313 | int height = qemu_console_get_height(con, 480); |
Gerd Hoffmann | 9588d67 | 2018-03-13 11:17:29 -0600 | [diff] [blame] | 1314 | |
| 1315 | trace_console_gfx_close(con->index); |
Markus Armbruster | 5325cc3 | 2020-07-07 18:05:54 +0200 | [diff] [blame] | 1316 | object_property_set_link(OBJECT(con), "device", NULL, &error_abort); |
Gerd Hoffmann | 9588d67 | 2018-03-13 11:17:29 -0600 | [diff] [blame] | 1317 | graphic_console_set_hwops(con, &unused_ops, NULL); |
| 1318 | |
| 1319 | if (con->gl) { |
| 1320 | dpy_gl_scanout_disable(con); |
| 1321 | } |
Akihiko Odaki | b5a087b | 2021-02-25 19:13:14 +0900 | [diff] [blame] | 1322 | surface = qemu_create_placeholder_surface(width, height, unplugged); |
Gerd Hoffmann | 9588d67 | 2018-03-13 11:17:29 -0600 | [diff] [blame] | 1323 | dpy_gfx_replace_surface(con, surface); |
| 1324 | } |
| 1325 | |
Gerd Hoffmann | 284d1c6 | 2013-03-15 15:45:54 +0100 | [diff] [blame] | 1326 | QemuConsole *qemu_console_lookup_by_index(unsigned int index) |
| 1327 | { |
Gerd Hoffmann | cd6cd8f | 2018-05-07 11:54:24 +0200 | [diff] [blame] | 1328 | QemuConsole *con; |
| 1329 | |
| 1330 | QTAILQ_FOREACH(con, &consoles, next) { |
| 1331 | if (con->index == index) { |
| 1332 | return con; |
| 1333 | } |
Gerd Hoffmann | 284d1c6 | 2013-03-15 15:45:54 +0100 | [diff] [blame] | 1334 | } |
Gerd Hoffmann | cd6cd8f | 2018-05-07 11:54:24 +0200 | [diff] [blame] | 1335 | return NULL; |
Gerd Hoffmann | 284d1c6 | 2013-03-15 15:45:54 +0100 | [diff] [blame] | 1336 | } |
| 1337 | |
Gerd Hoffmann | 5643706 | 2014-01-24 15:35:21 +0100 | [diff] [blame] | 1338 | QemuConsole *qemu_console_lookup_by_device(DeviceState *dev, uint32_t head) |
Gerd Hoffmann | 14a9364 | 2013-04-18 07:30:40 +0200 | [diff] [blame] | 1339 | { |
Gerd Hoffmann | cd6cd8f | 2018-05-07 11:54:24 +0200 | [diff] [blame] | 1340 | QemuConsole *con; |
Gerd Hoffmann | 14a9364 | 2013-04-18 07:30:40 +0200 | [diff] [blame] | 1341 | Object *obj; |
Gerd Hoffmann | 5643706 | 2014-01-24 15:35:21 +0100 | [diff] [blame] | 1342 | uint32_t h; |
Gerd Hoffmann | 14a9364 | 2013-04-18 07:30:40 +0200 | [diff] [blame] | 1343 | |
Gerd Hoffmann | cd6cd8f | 2018-05-07 11:54:24 +0200 | [diff] [blame] | 1344 | QTAILQ_FOREACH(con, &consoles, next) { |
| 1345 | obj = object_property_get_link(OBJECT(con), |
Kirill Batuzov | afff2b1 | 2014-04-24 18:15:58 +0400 | [diff] [blame] | 1346 | "device", &error_abort); |
Gerd Hoffmann | 5643706 | 2014-01-24 15:35:21 +0100 | [diff] [blame] | 1347 | if (DEVICE(obj) != dev) { |
| 1348 | continue; |
Gerd Hoffmann | 14a9364 | 2013-04-18 07:30:40 +0200 | [diff] [blame] | 1349 | } |
Gerd Hoffmann | cd6cd8f | 2018-05-07 11:54:24 +0200 | [diff] [blame] | 1350 | h = object_property_get_uint(OBJECT(con), |
Marc-André Lureau | ad664c1 | 2017-06-07 20:36:32 +0400 | [diff] [blame] | 1351 | "head", &error_abort); |
Gerd Hoffmann | 5643706 | 2014-01-24 15:35:21 +0100 | [diff] [blame] | 1352 | if (h != head) { |
| 1353 | continue; |
| 1354 | } |
Gerd Hoffmann | cd6cd8f | 2018-05-07 11:54:24 +0200 | [diff] [blame] | 1355 | return con; |
Gerd Hoffmann | 14a9364 | 2013-04-18 07:30:40 +0200 | [diff] [blame] | 1356 | } |
| 1357 | return NULL; |
| 1358 | } |
| 1359 | |
Gerd Hoffmann | f2c1d54 | 2016-01-12 11:45:43 +0100 | [diff] [blame] | 1360 | QemuConsole *qemu_console_lookup_by_device_name(const char *device_id, |
| 1361 | uint32_t head, Error **errp) |
| 1362 | { |
| 1363 | DeviceState *dev; |
| 1364 | QemuConsole *con; |
| 1365 | |
| 1366 | dev = qdev_find_recursive(sysbus_get_default(), device_id); |
| 1367 | if (dev == NULL) { |
| 1368 | error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, |
| 1369 | "Device '%s' not found", device_id); |
| 1370 | return NULL; |
| 1371 | } |
| 1372 | |
| 1373 | con = qemu_console_lookup_by_device(dev, head); |
| 1374 | if (con == NULL) { |
| 1375 | error_setg(errp, "Device %s (head %d) is not bound to a QemuConsole", |
| 1376 | device_id, head); |
| 1377 | return NULL; |
| 1378 | } |
| 1379 | |
| 1380 | return con; |
| 1381 | } |
| 1382 | |
Marc-André Lureau | f9411aa | 2023-08-30 13:37:57 +0400 | [diff] [blame] | 1383 | static QemuConsole *qemu_graphic_console_lookup_unused(void) |
Gerd Hoffmann | 9588d67 | 2018-03-13 11:17:29 -0600 | [diff] [blame] | 1384 | { |
Gerd Hoffmann | cd6cd8f | 2018-05-07 11:54:24 +0200 | [diff] [blame] | 1385 | QemuConsole *con; |
Gerd Hoffmann | 9588d67 | 2018-03-13 11:17:29 -0600 | [diff] [blame] | 1386 | Object *obj; |
Gerd Hoffmann | 9588d67 | 2018-03-13 11:17:29 -0600 | [diff] [blame] | 1387 | |
Gerd Hoffmann | cd6cd8f | 2018-05-07 11:54:24 +0200 | [diff] [blame] | 1388 | QTAILQ_FOREACH(con, &consoles, next) { |
Marc-André Lureau | f9411aa | 2023-08-30 13:37:57 +0400 | [diff] [blame] | 1389 | if (!QEMU_IS_GRAPHIC_CONSOLE(con) || con->hw_ops != &unused_ops) { |
Gerd Hoffmann | 9588d67 | 2018-03-13 11:17:29 -0600 | [diff] [blame] | 1390 | continue; |
| 1391 | } |
Gerd Hoffmann | cd6cd8f | 2018-05-07 11:54:24 +0200 | [diff] [blame] | 1392 | obj = object_property_get_link(OBJECT(con), |
Gerd Hoffmann | 9588d67 | 2018-03-13 11:17:29 -0600 | [diff] [blame] | 1393 | "device", &error_abort); |
| 1394 | if (obj != NULL) { |
| 1395 | continue; |
| 1396 | } |
Gerd Hoffmann | cd6cd8f | 2018-05-07 11:54:24 +0200 | [diff] [blame] | 1397 | return con; |
Gerd Hoffmann | 9588d67 | 2018-03-13 11:17:29 -0600 | [diff] [blame] | 1398 | } |
| 1399 | return NULL; |
| 1400 | } |
| 1401 | |
Marc-André Lureau | 385ac97 | 2023-01-17 15:24:40 +0400 | [diff] [blame] | 1402 | QEMUCursor *qemu_console_get_cursor(QemuConsole *con) |
| 1403 | { |
Marc-André Lureau | 3c293a4 | 2023-03-19 15:10:17 +0400 | [diff] [blame] | 1404 | if (con == NULL) { |
| 1405 | con = active_console; |
| 1406 | } |
Marc-André Lureau | 58d5870 | 2023-08-30 13:38:03 +0400 | [diff] [blame] | 1407 | return QEMU_IS_GRAPHIC_CONSOLE(con) ? QEMU_GRAPHIC_CONSOLE(con)->cursor : NULL; |
Marc-André Lureau | 385ac97 | 2023-01-17 15:24:40 +0400 | [diff] [blame] | 1408 | } |
| 1409 | |
Gerd Hoffmann | 81c0d5a | 2013-03-14 14:27:08 +0100 | [diff] [blame] | 1410 | bool qemu_console_is_visible(QemuConsole *con) |
pbrook | 9521989 | 2006-04-09 01:06:34 +0000 | [diff] [blame] | 1411 | { |
Gerd Hoffmann | 284d1c6 | 2013-03-15 15:45:54 +0100 | [diff] [blame] | 1412 | return (con == active_console) || (con->dcls > 0); |
bellard | e7f0ad5 | 2004-07-14 17:28:59 +0000 | [diff] [blame] | 1413 | } |
| 1414 | |
Gerd Hoffmann | 81c0d5a | 2013-03-14 14:27:08 +0100 | [diff] [blame] | 1415 | bool qemu_console_is_graphic(QemuConsole *con) |
balrog | c21bbcf | 2008-09-24 03:32:33 +0000 | [diff] [blame] | 1416 | { |
Gerd Hoffmann | 81c0d5a | 2013-03-14 14:27:08 +0100 | [diff] [blame] | 1417 | if (con == NULL) { |
| 1418 | con = active_console; |
| 1419 | } |
Marc-André Lureau | c105d60 | 2023-08-30 13:37:54 +0400 | [diff] [blame] | 1420 | return con && QEMU_IS_GRAPHIC_CONSOLE(con); |
Gerd Hoffmann | 81c0d5a | 2013-03-14 14:27:08 +0100 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | bool qemu_console_is_fixedsize(QemuConsole *con) |
| 1424 | { |
| 1425 | if (con == NULL) { |
| 1426 | con = active_console; |
| 1427 | } |
Marc-André Lureau | c105d60 | 2023-08-30 13:37:54 +0400 | [diff] [blame] | 1428 | return con && (QEMU_IS_GRAPHIC_CONSOLE(con) || QEMU_IS_FIXED_TEXT_CONSOLE(con)); |
balrog | c21bbcf | 2008-09-24 03:32:33 +0000 | [diff] [blame] | 1429 | } |
| 1430 | |
Gerd Hoffmann | f607867 | 2016-09-23 09:50:27 +0200 | [diff] [blame] | 1431 | bool qemu_console_is_gl_blocked(QemuConsole *con) |
| 1432 | { |
| 1433 | assert(con != NULL); |
| 1434 | return con->gl_block; |
| 1435 | } |
| 1436 | |
Wen, Jianxian | 839a482 | 2022-06-15 06:35:14 +0000 | [diff] [blame] | 1437 | bool qemu_console_is_multihead(DeviceState *dev) |
| 1438 | { |
| 1439 | QemuConsole *con; |
| 1440 | Object *obj; |
| 1441 | uint32_t f = 0xffffffff; |
| 1442 | uint32_t h; |
| 1443 | |
| 1444 | QTAILQ_FOREACH(con, &consoles, next) { |
| 1445 | obj = object_property_get_link(OBJECT(con), |
| 1446 | "device", &error_abort); |
| 1447 | if (DEVICE(obj) != dev) { |
| 1448 | continue; |
| 1449 | } |
| 1450 | |
| 1451 | h = object_property_get_uint(OBJECT(con), |
| 1452 | "head", &error_abort); |
| 1453 | if (f == 0xffffffff) { |
| 1454 | f = h; |
| 1455 | } else if (h != f) { |
| 1456 | return true; |
| 1457 | } |
| 1458 | } |
| 1459 | return false; |
| 1460 | } |
| 1461 | |
Gerd Hoffmann | 779ce88 | 2015-02-17 10:41:08 +0100 | [diff] [blame] | 1462 | char *qemu_console_get_label(QemuConsole *con) |
| 1463 | { |
Marc-André Lureau | c105d60 | 2023-08-30 13:37:54 +0400 | [diff] [blame] | 1464 | if (QEMU_IS_GRAPHIC_CONSOLE(con)) { |
Marc-André Lureau | 58d5870 | 2023-08-30 13:38:03 +0400 | [diff] [blame] | 1465 | QemuGraphicConsole *c = QEMU_GRAPHIC_CONSOLE(con); |
| 1466 | if (c->device) { |
Wen, Jianxian | 839a482 | 2022-06-15 06:35:14 +0000 | [diff] [blame] | 1467 | DeviceState *dev; |
| 1468 | bool multihead; |
| 1469 | |
Marc-André Lureau | 58d5870 | 2023-08-30 13:38:03 +0400 | [diff] [blame] | 1470 | dev = DEVICE(c->device); |
Wen, Jianxian | 839a482 | 2022-06-15 06:35:14 +0000 | [diff] [blame] | 1471 | multihead = qemu_console_is_multihead(dev); |
| 1472 | if (multihead) { |
| 1473 | return g_strdup_printf("%s.%d", dev->id ? |
| 1474 | dev->id : |
Marc-André Lureau | 58d5870 | 2023-08-30 13:38:03 +0400 | [diff] [blame] | 1475 | object_get_typename(c->device), |
| 1476 | c->head); |
Wen, Jianxian | 839a482 | 2022-06-15 06:35:14 +0000 | [diff] [blame] | 1477 | } else { |
| 1478 | return g_strdup_printf("%s", dev->id ? |
| 1479 | dev->id : |
Marc-André Lureau | 58d5870 | 2023-08-30 13:38:03 +0400 | [diff] [blame] | 1480 | object_get_typename(c->device)); |
Wen, Jianxian | 839a482 | 2022-06-15 06:35:14 +0000 | [diff] [blame] | 1481 | } |
Gerd Hoffmann | 779ce88 | 2015-02-17 10:41:08 +0100 | [diff] [blame] | 1482 | } |
| 1483 | return g_strdup("VGA"); |
Marc-André Lureau | b2bb9cc | 2023-08-30 13:38:02 +0400 | [diff] [blame] | 1484 | } else if (QEMU_IS_TEXT_CONSOLE(con)) { |
Marc-André Lureau | f7ce755 | 2023-08-30 13:38:22 +0400 | [diff] [blame] | 1485 | const char *label = qemu_text_console_get_label(QEMU_TEXT_CONSOLE(con)); |
| 1486 | if (label) { |
| 1487 | return g_strdup(label); |
Gerd Hoffmann | 779ce88 | 2015-02-17 10:41:08 +0100 | [diff] [blame] | 1488 | } |
Gerd Hoffmann | 779ce88 | 2015-02-17 10:41:08 +0100 | [diff] [blame] | 1489 | } |
Marc-André Lureau | b2bb9cc | 2023-08-30 13:38:02 +0400 | [diff] [blame] | 1490 | |
| 1491 | return g_strdup_printf("vc%d", con->index); |
Gerd Hoffmann | 779ce88 | 2015-02-17 10:41:08 +0100 | [diff] [blame] | 1492 | } |
| 1493 | |
Gerd Hoffmann | d4c8533 | 2013-11-28 09:58:18 +0100 | [diff] [blame] | 1494 | int qemu_console_get_index(QemuConsole *con) |
| 1495 | { |
| 1496 | if (con == NULL) { |
| 1497 | con = active_console; |
| 1498 | } |
| 1499 | return con ? con->index : -1; |
| 1500 | } |
| 1501 | |
Gerd Hoffmann | 5643706 | 2014-01-24 15:35:21 +0100 | [diff] [blame] | 1502 | uint32_t qemu_console_get_head(QemuConsole *con) |
| 1503 | { |
| 1504 | if (con == NULL) { |
| 1505 | con = active_console; |
| 1506 | } |
Marc-André Lureau | 58d5870 | 2023-08-30 13:38:03 +0400 | [diff] [blame] | 1507 | if (con == NULL) { |
| 1508 | return -1; |
| 1509 | } |
| 1510 | if (QEMU_IS_GRAPHIC_CONSOLE(con)) { |
| 1511 | return QEMU_GRAPHIC_CONSOLE(con)->head; |
| 1512 | } |
| 1513 | return 0; |
Gerd Hoffmann | 5643706 | 2014-01-24 15:35:21 +0100 | [diff] [blame] | 1514 | } |
| 1515 | |
Gerd Hoffmann | d4c8533 | 2013-11-28 09:58:18 +0100 | [diff] [blame] | 1516 | int qemu_console_get_width(QemuConsole *con, int fallback) |
| 1517 | { |
| 1518 | if (con == NULL) { |
| 1519 | con = active_console; |
| 1520 | } |
Marc-André Lureau | ebced09 | 2021-02-20 16:23:03 +0400 | [diff] [blame] | 1521 | if (con == NULL) { |
| 1522 | return fallback; |
| 1523 | } |
| 1524 | switch (con->scanout.kind) { |
| 1525 | case SCANOUT_DMABUF: |
| 1526 | return con->scanout.dmabuf->width; |
| 1527 | case SCANOUT_TEXTURE: |
| 1528 | return con->scanout.texture.width; |
| 1529 | case SCANOUT_SURFACE: |
| 1530 | return surface_width(con->surface); |
| 1531 | default: |
| 1532 | return fallback; |
| 1533 | } |
Gerd Hoffmann | d4c8533 | 2013-11-28 09:58:18 +0100 | [diff] [blame] | 1534 | } |
| 1535 | |
| 1536 | int qemu_console_get_height(QemuConsole *con, int fallback) |
| 1537 | { |
| 1538 | if (con == NULL) { |
| 1539 | con = active_console; |
| 1540 | } |
Marc-André Lureau | ebced09 | 2021-02-20 16:23:03 +0400 | [diff] [blame] | 1541 | if (con == NULL) { |
| 1542 | return fallback; |
| 1543 | } |
| 1544 | switch (con->scanout.kind) { |
| 1545 | case SCANOUT_DMABUF: |
| 1546 | return con->scanout.dmabuf->height; |
| 1547 | case SCANOUT_TEXTURE: |
| 1548 | return con->scanout.texture.height; |
| 1549 | case SCANOUT_SURFACE: |
| 1550 | return surface_height(con->surface); |
| 1551 | default: |
| 1552 | return fallback; |
| 1553 | } |
Gerd Hoffmann | d4c8533 | 2013-11-28 09:58:18 +0100 | [diff] [blame] | 1554 | } |
| 1555 | |
Marc-André Lureau | 322dae4 | 2023-08-30 13:38:16 +0400 | [diff] [blame] | 1556 | int qemu_invalidate_text_consoles(void) |
Jan Kiszka | bf1bed8 | 2012-07-10 22:00:55 +0200 | [diff] [blame] | 1557 | { |
Gerd Hoffmann | aea7947 | 2014-05-22 11:27:13 +0200 | [diff] [blame] | 1558 | QemuConsole *s; |
Gerd Hoffmann | cd6cd8f | 2018-05-07 11:54:24 +0200 | [diff] [blame] | 1559 | int count = 0; |
Jan Kiszka | bf1bed8 | 2012-07-10 22:00:55 +0200 | [diff] [blame] | 1560 | |
Gerd Hoffmann | cd6cd8f | 2018-05-07 11:54:24 +0200 | [diff] [blame] | 1561 | QTAILQ_FOREACH(s, &consoles, next) { |
Gerd Hoffmann | aea7947 | 2014-05-22 11:27:13 +0200 | [diff] [blame] | 1562 | if (qemu_console_is_graphic(s) || |
| 1563 | !qemu_console_is_visible(s)) { |
| 1564 | continue; |
| 1565 | } |
| 1566 | count++; |
| 1567 | graphic_hw_invalidate(s); |
| 1568 | } |
| 1569 | |
Marc-André Lureau | 322dae4 | 2023-08-30 13:38:16 +0400 | [diff] [blame] | 1570 | return count; |
| 1571 | } |
| 1572 | |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 1573 | void qemu_console_resize(QemuConsole *s, int width, int height) |
pbrook | c60e08d | 2008-07-01 16:24:38 +0000 | [diff] [blame] | 1574 | { |
Marc-André Lureau | 88738ea | 2022-07-25 15:58:15 +0400 | [diff] [blame] | 1575 | DisplaySurface *surface = qemu_console_surface(s); |
Gerd Hoffmann | 321f048 | 2013-03-12 14:39:22 +0100 | [diff] [blame] | 1576 | |
Marc-André Lureau | c105d60 | 2023-08-30 13:37:54 +0400 | [diff] [blame] | 1577 | assert(QEMU_IS_GRAPHIC_CONSOLE(s)); |
Marc-André Lureau | cd958ed | 2016-08-26 13:47:11 +0400 | [diff] [blame] | 1578 | |
Marc-André Lureau | 88738ea | 2022-07-25 15:58:15 +0400 | [diff] [blame] | 1579 | if ((s->scanout.kind != SCANOUT_SURFACE || |
| 1580 | (surface && surface->flags & QEMU_ALLOCATED_FLAG)) && |
| 1581 | qemu_console_get_width(s, -1) == width && |
Marc-André Lureau | cb8962c | 2022-02-15 00:13:37 +0400 | [diff] [blame] | 1582 | qemu_console_get_height(s, -1) == height) { |
Marc-André Lureau | cd958ed | 2016-08-26 13:47:11 +0400 | [diff] [blame] | 1583 | return; |
| 1584 | } |
| 1585 | |
Gerd Hoffmann | 321f048 | 2013-03-12 14:39:22 +0100 | [diff] [blame] | 1586 | surface = qemu_create_displaysurface(width, height); |
| 1587 | dpy_gfx_replace_surface(s, surface); |
pbrook | c60e08d | 2008-07-01 16:24:38 +0000 | [diff] [blame] | 1588 | } |
balrog | 38334f7 | 2008-09-24 02:21:24 +0000 | [diff] [blame] | 1589 | |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 1590 | DisplaySurface *qemu_console_surface(QemuConsole *console) |
| 1591 | { |
Marc-André Lureau | ebced09 | 2021-02-20 16:23:03 +0400 | [diff] [blame] | 1592 | switch (console->scanout.kind) { |
| 1593 | case SCANOUT_SURFACE: |
| 1594 | return console->surface; |
| 1595 | default: |
| 1596 | return NULL; |
| 1597 | } |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 1598 | } |
| 1599 | |
malc | 0da2ea1 | 2009-01-23 19:56:19 +0000 | [diff] [blame] | 1600 | PixelFormat qemu_default_pixelformat(int bpp) |
| 1601 | { |
Gerd Hoffmann | 56bd9ea | 2014-06-18 11:07:50 +0200 | [diff] [blame] | 1602 | pixman_format_code_t fmt = qemu_default_pixman_format(bpp, true); |
| 1603 | PixelFormat pf = qemu_pixelformat_from_pixman(fmt); |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 1604 | return pf; |
| 1605 | } |
Anthony Liguori | 01f45d9 | 2013-03-05 23:21:32 +0530 | [diff] [blame] | 1606 | |
Gerd Hoffmann | db71589 | 2018-03-01 11:05:35 +0100 | [diff] [blame] | 1607 | static QemuDisplay *dpys[DISPLAY_TYPE__MAX]; |
| 1608 | |
| 1609 | void qemu_display_register(QemuDisplay *ui) |
| 1610 | { |
| 1611 | assert(ui->type < DISPLAY_TYPE__MAX); |
| 1612 | dpys[ui->type] = ui; |
| 1613 | } |
| 1614 | |
Gerd Hoffmann | 898f9d4 | 2018-03-01 11:05:40 +0100 | [diff] [blame] | 1615 | bool qemu_display_find_default(DisplayOptions *opts) |
| 1616 | { |
| 1617 | static DisplayType prio[] = { |
Thomas Huth | 66c2207 | 2021-06-15 11:04:39 +0200 | [diff] [blame] | 1618 | #if defined(CONFIG_GTK) |
Gerd Hoffmann | 898f9d4 | 2018-03-01 11:05:40 +0100 | [diff] [blame] | 1619 | DISPLAY_TYPE_GTK, |
Thomas Huth | 66c2207 | 2021-06-15 11:04:39 +0200 | [diff] [blame] | 1620 | #endif |
| 1621 | #if defined(CONFIG_SDL) |
Gerd Hoffmann | 898f9d4 | 2018-03-01 11:05:40 +0100 | [diff] [blame] | 1622 | DISPLAY_TYPE_SDL, |
Thomas Huth | 66c2207 | 2021-06-15 11:04:39 +0200 | [diff] [blame] | 1623 | #endif |
| 1624 | #if defined(CONFIG_COCOA) |
Gerd Hoffmann | 898f9d4 | 2018-03-01 11:05:40 +0100 | [diff] [blame] | 1625 | DISPLAY_TYPE_COCOA |
Thomas Huth | 66c2207 | 2021-06-15 11:04:39 +0200 | [diff] [blame] | 1626 | #endif |
Gerd Hoffmann | 898f9d4 | 2018-03-01 11:05:40 +0100 | [diff] [blame] | 1627 | }; |
| 1628 | int i; |
| 1629 | |
Thomas Huth | 66c2207 | 2021-06-15 11:04:39 +0200 | [diff] [blame] | 1630 | for (i = 0; i < (int)ARRAY_SIZE(prio); i++) { |
Gerd Hoffmann | 898f9d4 | 2018-03-01 11:05:40 +0100 | [diff] [blame] | 1631 | if (dpys[prio[i]] == NULL) { |
Claudio Fontana | c551fb0 | 2022-09-29 11:30:33 +0200 | [diff] [blame] | 1632 | Error *local_err = NULL; |
| 1633 | int rv = ui_module_load(DisplayType_str(prio[i]), &local_err); |
| 1634 | if (rv < 0) { |
| 1635 | error_report_err(local_err); |
| 1636 | } |
Gerd Hoffmann | 61b4d9a | 2018-03-01 11:05:41 +0100 | [diff] [blame] | 1637 | } |
| 1638 | if (dpys[prio[i]] == NULL) { |
Gerd Hoffmann | 898f9d4 | 2018-03-01 11:05:40 +0100 | [diff] [blame] | 1639 | continue; |
| 1640 | } |
| 1641 | opts->type = prio[i]; |
| 1642 | return true; |
| 1643 | } |
| 1644 | return false; |
| 1645 | } |
| 1646 | |
Gerd Hoffmann | db71589 | 2018-03-01 11:05:35 +0100 | [diff] [blame] | 1647 | void qemu_display_early_init(DisplayOptions *opts) |
| 1648 | { |
| 1649 | assert(opts->type < DISPLAY_TYPE__MAX); |
| 1650 | if (opts->type == DISPLAY_TYPE_NONE) { |
| 1651 | return; |
| 1652 | } |
| 1653 | if (dpys[opts->type] == NULL) { |
Claudio Fontana | c551fb0 | 2022-09-29 11:30:33 +0200 | [diff] [blame] | 1654 | Error *local_err = NULL; |
| 1655 | int rv = ui_module_load(DisplayType_str(opts->type), &local_err); |
| 1656 | if (rv < 0) { |
| 1657 | error_report_err(local_err); |
| 1658 | } |
Gerd Hoffmann | 61b4d9a | 2018-03-01 11:05:41 +0100 | [diff] [blame] | 1659 | } |
| 1660 | if (dpys[opts->type] == NULL) { |
Gerd Hoffmann | db71589 | 2018-03-01 11:05:35 +0100 | [diff] [blame] | 1661 | error_report("Display '%s' is not available.", |
Marc-André Lureau | c809d1d | 2018-08-01 11:25:08 +0200 | [diff] [blame] | 1662 | DisplayType_str(opts->type)); |
Gerd Hoffmann | db71589 | 2018-03-01 11:05:35 +0100 | [diff] [blame] | 1663 | exit(1); |
| 1664 | } |
| 1665 | if (dpys[opts->type]->early_init) { |
| 1666 | dpys[opts->type]->early_init(opts); |
| 1667 | } |
| 1668 | } |
| 1669 | |
| 1670 | void qemu_display_init(DisplayState *ds, DisplayOptions *opts) |
| 1671 | { |
| 1672 | assert(opts->type < DISPLAY_TYPE__MAX); |
| 1673 | if (opts->type == DISPLAY_TYPE_NONE) { |
| 1674 | return; |
| 1675 | } |
| 1676 | assert(dpys[opts->type] != NULL); |
| 1677 | dpys[opts->type]->init(ds, opts); |
| 1678 | } |
| 1679 | |
Thomas Huth | c388f40 | 2020-01-08 15:47:02 +0100 | [diff] [blame] | 1680 | void qemu_display_help(void) |
| 1681 | { |
| 1682 | int idx; |
| 1683 | |
| 1684 | printf("Available display backend types:\n"); |
Philippe Mathieu-Daudé | a1e8853 | 2020-01-20 20:29:47 +0100 | [diff] [blame] | 1685 | printf("none\n"); |
Thomas Huth | c388f40 | 2020-01-08 15:47:02 +0100 | [diff] [blame] | 1686 | for (idx = DISPLAY_TYPE_NONE; idx < DISPLAY_TYPE__MAX; idx++) { |
| 1687 | if (!dpys[idx]) { |
Claudio Fontana | c551fb0 | 2022-09-29 11:30:33 +0200 | [diff] [blame] | 1688 | Error *local_err = NULL; |
| 1689 | int rv = ui_module_load(DisplayType_str(idx), &local_err); |
| 1690 | if (rv < 0) { |
| 1691 | error_report_err(local_err); |
| 1692 | } |
Thomas Huth | c388f40 | 2020-01-08 15:47:02 +0100 | [diff] [blame] | 1693 | } |
| 1694 | if (dpys[idx]) { |
| 1695 | printf("%s\n", DisplayType_str(dpys[idx]->type)); |
| 1696 | } |
| 1697 | } |
| 1698 | } |