blob: f7a428c86a8d3b23e808cd0d94ab389fb18c9b48 [file] [log] [blame]
Gerd Hoffmann97edf3b2015-01-20 12:43:28 +01001/*
2 * GTK UI -- egl opengl code.
3 *
4 * Note that gtk 3.16+ (released 2015-03-23) has a GtkGLArea widget,
5 * which is GtkDrawingArea like widget with opengl rendering support.
6 *
7 * This code handles opengl support on older gtk versions, using egl
8 * to get a opengl context for the X11 window.
9 *
10 * This work is licensed under the terms of the GNU GPL, version 2 or later.
11 * See the COPYING file in the top-level directory.
12 */
13
Peter Maydelle16f4c82016-01-29 17:49:51 +000014#include "qemu/osdep.h"
Vivek Kasireddy65b847d2021-09-14 14:18:35 -070015#include "qemu/main-loop.h"
Marc-André Lureau1d48c9f2023-06-06 15:56:39 +040016#include "qemu/error-report.h"
Gerd Hoffmann97edf3b2015-01-20 12:43:28 +010017
18#include "trace.h"
19
20#include "ui/console.h"
21#include "ui/gtk.h"
22#include "ui/egl-helpers.h"
Gerd Hoffmannf1bd3132018-03-06 10:09:51 +010023#include "ui/shader.h"
Gerd Hoffmann97edf3b2015-01-20 12:43:28 +010024
Philippe Mathieu-Daudé32cad1f2024-12-03 15:20:13 +010025#include "system/system.h"
Gerd Hoffmann97edf3b2015-01-20 12:43:28 +010026
Gerd Hoffmann4782aeb2015-05-08 11:30:51 +020027static void gtk_egl_set_scanout_mode(VirtualConsole *vc, bool scanout)
28{
29 if (vc->gfx.scanout_mode == scanout) {
30 return;
31 }
32
33 vc->gfx.scanout_mode = scanout;
34 if (!vc->gfx.scanout_mode) {
Dongwon Kim83b4b232023-06-28 12:15:04 -070035 eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
36 vc->gfx.esurface, vc->gfx.ectx);
Gerd Hoffmanna4f113f2017-06-14 10:41:49 +020037 egl_fb_destroy(&vc->gfx.guest_fb);
Gerd Hoffmann4782aeb2015-05-08 11:30:51 +020038 if (vc->gfx.surface) {
39 surface_gl_destroy_texture(vc->gfx.gls, vc->gfx.ds);
40 surface_gl_create_texture(vc->gfx.gls, vc->gfx.ds);
41 }
42 }
43}
44
Gerd Hoffmann97edf3b2015-01-20 12:43:28 +010045/** DisplayState Callbacks (opengl version) **/
46
47void gd_egl_init(VirtualConsole *vc)
48{
49 GdkWindow *gdk_window = gtk_widget_get_window(vc->gfx.drawing_area);
50 if (!gdk_window) {
51 return;
52 }
53
Gerd Hoffmann97edf3b2015-01-20 12:43:28 +010054 Window x11_window = gdk_x11_window_get_xid(gdk_window);
Gerd Hoffmann97edf3b2015-01-20 12:43:28 +010055 if (!x11_window) {
56 return;
57 }
58
59 vc->gfx.ectx = qemu_egl_init_ctx();
Alexander Kanavinfbd57c72019-01-16 12:37:51 +010060 vc->gfx.esurface = qemu_egl_init_surface_x11
61 (vc->gfx.ectx, (EGLNativeWindowType)x11_window);
Gerd Hoffmann97edf3b2015-01-20 12:43:28 +010062
63 assert(vc->gfx.esurface);
64}
65
66void gd_egl_draw(VirtualConsole *vc)
67{
68 GdkWindow *window;
Dongwon Kim55f4b762021-09-24 15:51:05 -070069#ifdef CONFIG_GBM
70 QemuDmaBuf *dmabuf = vc->gfx.guest_fb.dmabuf;
Cédric Le Goater3dba3c02024-05-15 12:05:20 +020071 int fence_fd;
Dongwon Kim55f4b762021-09-24 15:51:05 -070072#endif
Dongwon Kim47fd6ab2023-10-12 15:26:43 -070073 int ww, wh, ws;
Gerd Hoffmann97edf3b2015-01-20 12:43:28 +010074
Gerd Hoffmann4782aeb2015-05-08 11:30:51 +020075 if (!vc->gfx.gls) {
Gerd Hoffmann97edf3b2015-01-20 12:43:28 +010076 return;
77 }
78
Gerd Hoffmannf1aba962018-11-07 08:49:49 +010079 window = gtk_widget_get_window(vc->gfx.drawing_area);
Dongwon Kim47fd6ab2023-10-12 15:26:43 -070080 ws = gdk_window_get_scale_factor(window);
81 ww = gdk_window_get_width(window) * ws;
82 wh = gdk_window_get_height(window) * ws;
Gerd Hoffmannf1aba962018-11-07 08:49:49 +010083
Gerd Hoffmann4782aeb2015-05-08 11:30:51 +020084 if (vc->gfx.scanout_mode) {
Dongwon Kim55f4b762021-09-24 15:51:05 -070085#ifdef CONFIG_GBM
86 if (dmabuf) {
Dongwon Kim6779a302024-05-08 10:54:00 -070087 if (!qemu_dmabuf_get_draw_submitted(dmabuf)) {
Dongwon Kim55f4b762021-09-24 15:51:05 -070088 return;
89 } else {
Dongwon Kimfa642682024-05-08 10:54:01 -070090 qemu_dmabuf_set_draw_submitted(dmabuf, false);
Dongwon Kim55f4b762021-09-24 15:51:05 -070091 }
92 }
93#endif
Gerd Hoffmann4782aeb2015-05-08 11:30:51 +020094 gd_egl_scanout_flush(&vc->gfx.dcl, 0, 0, vc->gfx.w, vc->gfx.h);
Gerd Hoffmannf1aba962018-11-07 08:49:49 +010095
Erico Nunesf8a951b2023-03-20 17:08:56 +010096 vc->gfx.scale_x = (double)ww / surface_width(vc->gfx.ds);
97 vc->gfx.scale_y = (double)wh / surface_height(vc->gfx.ds);
Dongwon Kim55f4b762021-09-24 15:51:05 -070098
99 glFlush();
100#ifdef CONFIG_GBM
101 if (dmabuf) {
102 egl_dmabuf_create_fence(dmabuf);
Dongwon Kim6779a302024-05-08 10:54:00 -0700103 fence_fd = qemu_dmabuf_get_fence_fd(dmabuf);
104 if (fence_fd >= 0) {
105 qemu_set_fd_handler(fence_fd, gd_hw_gl_flushed, NULL, vc);
Dongwon Kim55f4b762021-09-24 15:51:05 -0700106 return;
107 }
108 graphic_hw_gl_block(vc->gfx.dcl.con, false);
109 }
110#endif
Gerd Hoffmann4782aeb2015-05-08 11:30:51 +0200111 } else {
112 if (!vc->gfx.ds) {
113 return;
114 }
115 eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
116 vc->gfx.esurface, vc->gfx.ectx);
Gerd Hoffmann97edf3b2015-01-20 12:43:28 +0100117
Gerd Hoffmann4782aeb2015-05-08 11:30:51 +0200118 surface_gl_setup_viewport(vc->gfx.gls, vc->gfx.ds, ww, wh);
119 surface_gl_render_texture(vc->gfx.gls, vc->gfx.ds);
Gerd Hoffmann97edf3b2015-01-20 12:43:28 +0100120
Gerd Hoffmann4782aeb2015-05-08 11:30:51 +0200121 eglSwapBuffers(qemu_egl_display, vc->gfx.esurface);
Gerd Hoffmannf1aba962018-11-07 08:49:49 +0100122
123 vc->gfx.scale_x = (double)ww / surface_width(vc->gfx.ds);
124 vc->gfx.scale_y = (double)wh / surface_height(vc->gfx.ds);
Dongwon Kim55f4b762021-09-24 15:51:05 -0700125
126 glFlush();
Gerd Hoffmann4782aeb2015-05-08 11:30:51 +0200127 }
Gerd Hoffmann97edf3b2015-01-20 12:43:28 +0100128}
129
130void gd_egl_update(DisplayChangeListener *dcl,
131 int x, int y, int w, int h)
132{
133 VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
134
135 if (!vc->gfx.gls || !vc->gfx.ds) {
136 return;
137 }
138
139 eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
140 vc->gfx.esurface, vc->gfx.ectx);
141 surface_gl_update_texture(vc->gfx.gls, vc->gfx.ds, x, y, w, h);
142 vc->gfx.glupdates++;
Dongwon Kim83b4b232023-06-28 12:15:04 -0700143 eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE,
144 EGL_NO_SURFACE, EGL_NO_CONTEXT);
Gerd Hoffmann97edf3b2015-01-20 12:43:28 +0100145}
146
147void gd_egl_refresh(DisplayChangeListener *dcl)
148{
149 VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
150
Akihiko Odakiaeffd072022-02-26 20:55:15 +0900151 gd_update_monitor_refresh_rate(
152 vc, vc->window ? vc->window : vc->gfx.drawing_area);
Nikola Pavlicacab82422021-01-14 15:01:53 +0100153
Dongwon Kim6779a302024-05-08 10:54:00 -0700154 if (vc->gfx.guest_fb.dmabuf &&
155 qemu_dmabuf_get_draw_submitted(vc->gfx.guest_fb.dmabuf)) {
Dongwon Kim77bf3102024-04-26 15:50:59 -0700156 gd_egl_draw(vc);
Dongwon Kim1be878e2023-07-06 11:33:55 -0700157 return;
158 }
159
Gerd Hoffmann97edf3b2015-01-20 12:43:28 +0100160 if (!vc->gfx.esurface) {
161 gd_egl_init(vc);
162 if (!vc->gfx.esurface) {
163 return;
164 }
Gerd Hoffmann46e19e12017-10-10 15:54:49 +0200165 vc->gfx.gls = qemu_gl_init_shader();
Gerd Hoffmann97edf3b2015-01-20 12:43:28 +0100166 if (vc->gfx.ds) {
Dongwon Kim01eb4742021-11-03 23:51:49 -0700167 surface_gl_destroy_texture(vc->gfx.gls, vc->gfx.ds);
Gerd Hoffmann97edf3b2015-01-20 12:43:28 +0100168 surface_gl_create_texture(vc->gfx.gls, vc->gfx.ds);
169 }
Philippe Mathieu-Daudé8b4ed0d2021-11-08 09:31:29 +0100170#ifdef CONFIG_GBM
Dongwon Kim4872a022021-11-03 23:51:50 -0700171 if (vc->gfx.guest_fb.dmabuf) {
172 egl_dmabuf_release_texture(vc->gfx.guest_fb.dmabuf);
173 gd_egl_scanout_dmabuf(dcl, vc->gfx.guest_fb.dmabuf);
174 }
Philippe Mathieu-Daudé8b4ed0d2021-11-08 09:31:29 +0100175#endif
Gerd Hoffmann97edf3b2015-01-20 12:43:28 +0100176 }
177
178 graphic_hw_update(dcl->con);
179
180 if (vc->gfx.glupdates) {
181 vc->gfx.glupdates = 0;
Gerd Hoffmann4782aeb2015-05-08 11:30:51 +0200182 gtk_egl_set_scanout_mode(vc, false);
Gerd Hoffmann97edf3b2015-01-20 12:43:28 +0100183 gd_egl_draw(vc);
184 }
185}
186
187void gd_egl_switch(DisplayChangeListener *dcl,
188 DisplaySurface *surface)
189{
190 VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
191 bool resized = true;
192
193 trace_gd_switch(vc->label, surface_width(surface), surface_height(surface));
194
195 if (vc->gfx.ds &&
196 surface_width(vc->gfx.ds) == surface_width(surface) &&
197 surface_height(vc->gfx.ds) == surface_height(surface)) {
198 resized = false;
199 }
Dongwon Kim01eb4742021-11-03 23:51:49 -0700200 eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
201 vc->gfx.esurface, vc->gfx.ectx);
Gerd Hoffmann97edf3b2015-01-20 12:43:28 +0100202
203 surface_gl_destroy_texture(vc->gfx.gls, vc->gfx.ds);
204 vc->gfx.ds = surface;
205 if (vc->gfx.gls) {
206 surface_gl_create_texture(vc->gfx.gls, vc->gfx.ds);
207 }
208
209 if (resized) {
210 gd_update_windowsize(vc);
211 }
Dongwon Kim604a8682022-09-28 14:58:05 -0700212
213 eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
214 EGL_NO_CONTEXT);
Gerd Hoffmann97edf3b2015-01-20 12:43:28 +0100215}
216
Marc-André Lureau5e79d512021-10-09 23:48:46 +0400217QEMUGLContext gd_egl_create_context(DisplayGLCtx *dgc,
Gerd Hoffmann4782aeb2015-05-08 11:30:51 +0200218 QEMUGLParams *params)
219{
Marc-André Lureau5e79d512021-10-09 23:48:46 +0400220 VirtualConsole *vc = container_of(dgc, VirtualConsole, gfx.dgc);
Gerd Hoffmann4782aeb2015-05-08 11:30:51 +0200221
222 eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
223 vc->gfx.esurface, vc->gfx.ectx);
Marc-André Lureau5e79d512021-10-09 23:48:46 +0400224 return qemu_egl_create_context(dgc, params);
Gerd Hoffmann4782aeb2015-05-08 11:30:51 +0200225}
226
Gerd Hoffmann543a7a12017-02-21 10:37:21 +0100227void gd_egl_scanout_disable(DisplayChangeListener *dcl)
228{
229 VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
230
231 vc->gfx.w = 0;
232 vc->gfx.h = 0;
Gerd Hoffmann543a7a12017-02-21 10:37:21 +0100233 gtk_egl_set_scanout_mode(vc, false);
234}
235
Gerd Hoffmannf4c36bd2017-02-21 10:37:16 +0100236void gd_egl_scanout_texture(DisplayChangeListener *dcl,
237 uint32_t backing_id, bool backing_y_0_top,
238 uint32_t backing_width, uint32_t backing_height,
239 uint32_t x, uint32_t y,
Marc-André Lureaubf41ab62023-06-06 15:56:56 +0400240 uint32_t w, uint32_t h,
241 void *d3d_tex2d)
Gerd Hoffmann4782aeb2015-05-08 11:30:51 +0200242{
243 VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
244
245 vc->gfx.x = x;
246 vc->gfx.y = y;
247 vc->gfx.w = w;
248 vc->gfx.h = h;
Gerd Hoffmann4782aeb2015-05-08 11:30:51 +0200249 vc->gfx.y0_top = backing_y_0_top;
250
Antonio Caggiano6f189a02023-10-16 14:32:15 +0200251 if (!vc->gfx.esurface) {
252 gd_egl_init(vc);
253 if (!vc->gfx.esurface) {
254 return;
255 }
Antonio Caggiano6f189a02023-10-16 14:32:15 +0200256 }
Volker Rümelin53a939f2023-11-11 11:40:20 +0100257
258 eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
259 vc->gfx.esurface, vc->gfx.ectx);
260
261 gtk_egl_set_scanout_mode(vc, true);
262 egl_fb_setup_for_tex(&vc->gfx.guest_fb, backing_width, backing_height,
263 backing_id, false);
Gerd Hoffmann4782aeb2015-05-08 11:30:51 +0200264}
265
Gerd Hoffmann70763fe2018-03-06 10:09:50 +0100266void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl,
267 QemuDmaBuf *dmabuf)
268{
Akihiko Odakibc6a3562021-02-23 15:03:07 +0900269#ifdef CONFIG_GBM
Vivek Kasireddy65b847d2021-09-14 14:18:35 -0700270 VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
Dongwon Kim6779a302024-05-08 10:54:00 -0700271 uint32_t x, y, width, height, backing_width, backing_height, texture;
272 bool y0_top;
Vivek Kasireddy65b847d2021-09-14 14:18:35 -0700273
Dongwon Kim01eb4742021-11-03 23:51:49 -0700274 eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
275 vc->gfx.esurface, vc->gfx.ectx);
276
Gerd Hoffmann70763fe2018-03-06 10:09:50 +0100277 egl_dmabuf_import_texture(dmabuf);
Dongwon Kim6779a302024-05-08 10:54:00 -0700278 texture = qemu_dmabuf_get_texture(dmabuf);
279 if (!texture) {
Gerd Hoffmann70763fe2018-03-06 10:09:50 +0100280 return;
281 }
282
Dongwon Kim6779a302024-05-08 10:54:00 -0700283 x = qemu_dmabuf_get_x(dmabuf);
284 y = qemu_dmabuf_get_y(dmabuf);
285 width = qemu_dmabuf_get_width(dmabuf);
286 height = qemu_dmabuf_get_height(dmabuf);
287 backing_width = qemu_dmabuf_get_backing_width(dmabuf);
288 backing_height = qemu_dmabuf_get_backing_height(dmabuf);
289 y0_top = qemu_dmabuf_get_y0_top(dmabuf);
Vivek Kasireddy65b847d2021-09-14 14:18:35 -0700290
Dongwon Kim6779a302024-05-08 10:54:00 -0700291 gd_egl_scanout_texture(dcl, texture, y0_top, backing_width, backing_height,
292 x, y, width, height, NULL);
293
294 if (qemu_dmabuf_get_allow_fences(dmabuf)) {
Vivek Kasireddy65b847d2021-09-14 14:18:35 -0700295 vc->gfx.guest_fb.dmabuf = dmabuf;
296 }
Gerd Hoffmann70763fe2018-03-06 10:09:50 +0100297#endif
298}
299
Gerd Hoffmannf1bd3132018-03-06 10:09:51 +0100300void gd_egl_cursor_dmabuf(DisplayChangeListener *dcl,
301 QemuDmaBuf *dmabuf, bool have_hot,
302 uint32_t hot_x, uint32_t hot_y)
303{
Akihiko Odakibc6a3562021-02-23 15:03:07 +0900304#ifdef CONFIG_GBM
Gerd Hoffmannf1bd3132018-03-06 10:09:51 +0100305 VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
Dongwon Kim6779a302024-05-08 10:54:00 -0700306 uint32_t backing_width, backing_height, texture;
Gerd Hoffmannf1bd3132018-03-06 10:09:51 +0100307
308 if (dmabuf) {
309 egl_dmabuf_import_texture(dmabuf);
Dongwon Kim6779a302024-05-08 10:54:00 -0700310 texture = qemu_dmabuf_get_texture(dmabuf);
311 if (!texture) {
Gerd Hoffmannf1bd3132018-03-06 10:09:51 +0100312 return;
313 }
Dongwon Kim6779a302024-05-08 10:54:00 -0700314
315 backing_width = qemu_dmabuf_get_backing_width(dmabuf);
316 backing_height = qemu_dmabuf_get_backing_height(dmabuf);
317 egl_fb_setup_for_tex(&vc->gfx.cursor_fb, backing_width, backing_height,
318 texture, false);
Gerd Hoffmannf1bd3132018-03-06 10:09:51 +0100319 } else {
320 egl_fb_destroy(&vc->gfx.cursor_fb);
321 }
322#endif
323}
324
325void gd_egl_cursor_position(DisplayChangeListener *dcl,
326 uint32_t pos_x, uint32_t pos_y)
327{
328 VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
329
Gerd Hoffmannf1aba962018-11-07 08:49:49 +0100330 vc->gfx.cursor_x = pos_x * vc->gfx.scale_x;
331 vc->gfx.cursor_y = pos_y * vc->gfx.scale_y;
Gerd Hoffmannf1bd3132018-03-06 10:09:51 +0100332}
333
Gerd Hoffmann4782aeb2015-05-08 11:30:51 +0200334void gd_egl_scanout_flush(DisplayChangeListener *dcl,
335 uint32_t x, uint32_t y, uint32_t w, uint32_t h)
336{
337 VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
338 GdkWindow *window;
Dongwon Kim47fd6ab2023-10-12 15:26:43 -0700339 int ww, wh, ws;
Gerd Hoffmann4782aeb2015-05-08 11:30:51 +0200340
341 if (!vc->gfx.scanout_mode) {
342 return;
343 }
Gerd Hoffmanna4f113f2017-06-14 10:41:49 +0200344 if (!vc->gfx.guest_fb.framebuffer) {
Gerd Hoffmann4782aeb2015-05-08 11:30:51 +0200345 return;
346 }
347
348 eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
349 vc->gfx.esurface, vc->gfx.ectx);
350
Gerd Hoffmann4782aeb2015-05-08 11:30:51 +0200351 window = gtk_widget_get_window(vc->gfx.drawing_area);
Dongwon Kim47fd6ab2023-10-12 15:26:43 -0700352 ws = gdk_window_get_scale_factor(window);
353 ww = gdk_window_get_width(window) * ws;
354 wh = gdk_window_get_height(window) * ws;
Gerd Hoffmanna4f113f2017-06-14 10:41:49 +0200355 egl_fb_setup_default(&vc->gfx.win_fb, ww, wh);
Gerd Hoffmannf1bd3132018-03-06 10:09:51 +0100356 if (vc->gfx.cursor_fb.texture) {
357 egl_texture_blit(vc->gfx.gls, &vc->gfx.win_fb, &vc->gfx.guest_fb,
358 vc->gfx.y0_top);
359 egl_texture_blend(vc->gfx.gls, &vc->gfx.win_fb, &vc->gfx.cursor_fb,
360 vc->gfx.y0_top,
Chen Zhang051a0cd2019-01-25 15:47:23 +0800361 vc->gfx.cursor_x, vc->gfx.cursor_y,
362 vc->gfx.scale_x, vc->gfx.scale_y);
Gerd Hoffmannf1bd3132018-03-06 10:09:51 +0100363 } else {
364 egl_fb_blit(&vc->gfx.win_fb, &vc->gfx.guest_fb, !vc->gfx.y0_top);
365 }
Gerd Hoffmann4782aeb2015-05-08 11:30:51 +0200366
Vivek Kasireddy65b847d2021-09-14 14:18:35 -0700367#ifdef CONFIG_GBM
368 if (vc->gfx.guest_fb.dmabuf) {
369 egl_dmabuf_create_sync(vc->gfx.guest_fb.dmabuf);
370 }
371#endif
372
Gerd Hoffmann4782aeb2015-05-08 11:30:51 +0200373 eglSwapBuffers(qemu_egl_display, vc->gfx.esurface);
374}
375
Vivek Kasireddyab971f82021-09-14 14:18:36 -0700376void gd_egl_flush(DisplayChangeListener *dcl,
377 uint32_t x, uint32_t y, uint32_t w, uint32_t h)
378{
379 VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
380 GtkWidget *area = vc->gfx.drawing_area;
381
Dongwon Kim6779a302024-05-08 10:54:00 -0700382 if (vc->gfx.guest_fb.dmabuf &&
383 !qemu_dmabuf_get_draw_submitted(vc->gfx.guest_fb.dmabuf)) {
Vivek Kasireddyab971f82021-09-14 14:18:36 -0700384 graphic_hw_gl_block(vc->gfx.dcl.con, true);
Dongwon Kimfa642682024-05-08 10:54:01 -0700385 qemu_dmabuf_set_draw_submitted(vc->gfx.guest_fb.dmabuf, true);
Dongwon Kim92b58152023-07-06 11:33:54 -0700386 gtk_egl_set_scanout_mode(vc, true);
Vivek Kasireddyab971f82021-09-14 14:18:36 -0700387 gtk_widget_queue_draw_area(area, x, y, w, h);
388 return;
389 }
390
391 gd_egl_scanout_flush(&vc->gfx.dcl, x, y, w, h);
392}
393
Gerd Hoffmann54d208f2018-06-18 13:21:41 +0200394void gtk_egl_init(DisplayGLMode mode)
Gerd Hoffmann97edf3b2015-01-20 12:43:28 +0100395{
396 GdkDisplay *gdk_display = gdk_display_get_default();
397 Display *x11_display = gdk_x11_display_get_xdisplay(gdk_display);
398
Gerd Hoffmann54d208f2018-06-18 13:21:41 +0200399 if (qemu_egl_init_dpy_x11(x11_display, mode) < 0) {
Gerd Hoffmann97edf3b2015-01-20 12:43:28 +0100400 return;
401 }
402
403 display_opengl = 1;
404}
Gerd Hoffmann4782aeb2015-05-08 11:30:51 +0200405
Marc-André Lureau5e79d512021-10-09 23:48:46 +0400406int gd_egl_make_current(DisplayGLCtx *dgc,
Gerd Hoffmann4782aeb2015-05-08 11:30:51 +0200407 QEMUGLContext ctx)
408{
Marc-André Lureau5e79d512021-10-09 23:48:46 +0400409 VirtualConsole *vc = container_of(dgc, VirtualConsole, gfx.dgc);
Gerd Hoffmann4782aeb2015-05-08 11:30:51 +0200410
Marc-André Lureau1d48c9f2023-06-06 15:56:39 +0400411 if (!eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
412 vc->gfx.esurface, ctx)) {
413 error_report("egl: eglMakeCurrent failed: %s", qemu_egl_get_error_string());
414 return -1;
415 }
416
417 return 0;
Gerd Hoffmann4782aeb2015-05-08 11:30:51 +0200418}