| 
									
										
										
										
											2015-01-20 12:43:28 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * GTK UI -- egl opengl code. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Note that gtk 3.16+ (released 2015-03-23) has a GtkGLArea widget, | 
					
						
							|  |  |  |  * which is GtkDrawingArea like widget with opengl rendering support. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This code handles opengl support on older gtk versions, using egl | 
					
						
							|  |  |  |  * to get a opengl context for the X11 window. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This work is licensed under the terms of the GNU GPL, version 2 or later. | 
					
						
							|  |  |  |  * See the COPYING file in the top-level directory. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-29 17:49:51 +00:00
										 |  |  | #include "qemu/osdep.h"
 | 
					
						
							| 
									
										
										
										
											2021-09-14 14:18:35 -07:00
										 |  |  | #include "qemu/main-loop.h"
 | 
					
						
							| 
									
										
										
										
											2023-06-06 15:56:39 +04:00
										 |  |  | #include "qemu/error-report.h"
 | 
					
						
							| 
									
										
										
										
											2015-01-20 12:43:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "trace.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "ui/console.h"
 | 
					
						
							|  |  |  | #include "ui/gtk.h"
 | 
					
						
							|  |  |  | #include "ui/egl-helpers.h"
 | 
					
						
							| 
									
										
										
										
											2018-03-06 10:09:51 +01:00
										 |  |  | #include "ui/shader.h"
 | 
					
						
							| 
									
										
										
										
											2015-01-20 12:43:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "sysemu/sysemu.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-08 11:30:51 +02:00
										 |  |  | static void gtk_egl_set_scanout_mode(VirtualConsole *vc, bool scanout) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (vc->gfx.scanout_mode == scanout) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     vc->gfx.scanout_mode = scanout; | 
					
						
							|  |  |  |     if (!vc->gfx.scanout_mode) { | 
					
						
							| 
									
										
										
										
											2023-06-28 12:15:04 -07:00
										 |  |  |         eglMakeCurrent(qemu_egl_display, vc->gfx.esurface, | 
					
						
							|  |  |  |                        vc->gfx.esurface, vc->gfx.ectx); | 
					
						
							| 
									
										
										
										
											2017-06-14 10:41:49 +02:00
										 |  |  |         egl_fb_destroy(&vc->gfx.guest_fb); | 
					
						
							| 
									
										
										
										
											2015-05-08 11:30:51 +02:00
										 |  |  |         if (vc->gfx.surface) { | 
					
						
							|  |  |  |             surface_gl_destroy_texture(vc->gfx.gls, vc->gfx.ds); | 
					
						
							|  |  |  |             surface_gl_create_texture(vc->gfx.gls, vc->gfx.ds); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-20 12:43:28 +01:00
										 |  |  | /** DisplayState Callbacks (opengl version) **/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void gd_egl_init(VirtualConsole *vc) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     GdkWindow *gdk_window = gtk_widget_get_window(vc->gfx.drawing_area); | 
					
						
							|  |  |  |     if (!gdk_window) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Window x11_window = gdk_x11_window_get_xid(gdk_window); | 
					
						
							|  |  |  |     if (!x11_window) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     vc->gfx.ectx = qemu_egl_init_ctx(); | 
					
						
							| 
									
										
										
										
											2019-01-16 12:37:51 +01:00
										 |  |  |     vc->gfx.esurface = qemu_egl_init_surface_x11 | 
					
						
							|  |  |  |         (vc->gfx.ectx, (EGLNativeWindowType)x11_window); | 
					
						
							| 
									
										
										
										
											2015-01-20 12:43:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     assert(vc->gfx.esurface); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void gd_egl_draw(VirtualConsole *vc) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     GdkWindow *window; | 
					
						
							| 
									
										
										
										
											2021-09-24 15:51:05 -07:00
										 |  |  | #ifdef CONFIG_GBM
 | 
					
						
							|  |  |  |     QemuDmaBuf *dmabuf = vc->gfx.guest_fb.dmabuf; | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2023-10-12 15:26:43 -07:00
										 |  |  |     int ww, wh, ws; | 
					
						
							| 
									
										
										
										
											2015-01-20 12:43:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-08 11:30:51 +02:00
										 |  |  |     if (!vc->gfx.gls) { | 
					
						
							| 
									
										
										
										
											2015-01-20 12:43:28 +01:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 08:49:49 +01:00
										 |  |  |     window = gtk_widget_get_window(vc->gfx.drawing_area); | 
					
						
							| 
									
										
										
										
											2023-10-12 15:26:43 -07:00
										 |  |  |     ws = gdk_window_get_scale_factor(window); | 
					
						
							|  |  |  |     ww = gdk_window_get_width(window) * ws; | 
					
						
							|  |  |  |     wh = gdk_window_get_height(window) * ws; | 
					
						
							| 
									
										
										
										
											2018-11-07 08:49:49 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-08 11:30:51 +02:00
										 |  |  |     if (vc->gfx.scanout_mode) { | 
					
						
							| 
									
										
										
										
											2021-09-24 15:51:05 -07:00
										 |  |  | #ifdef CONFIG_GBM
 | 
					
						
							|  |  |  |         if (dmabuf) { | 
					
						
							|  |  |  |             if (!dmabuf->draw_submitted) { | 
					
						
							|  |  |  |                 return; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 dmabuf->draw_submitted = false; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2015-05-08 11:30:51 +02:00
										 |  |  |         gd_egl_scanout_flush(&vc->gfx.dcl, 0, 0, vc->gfx.w, vc->gfx.h); | 
					
						
							| 
									
										
										
										
											2018-11-07 08:49:49 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-20 17:08:56 +01:00
										 |  |  |         vc->gfx.scale_x = (double)ww / surface_width(vc->gfx.ds); | 
					
						
							|  |  |  |         vc->gfx.scale_y = (double)wh / surface_height(vc->gfx.ds); | 
					
						
							| 
									
										
										
										
											2021-09-24 15:51:05 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         glFlush(); | 
					
						
							|  |  |  | #ifdef CONFIG_GBM
 | 
					
						
							|  |  |  |         if (dmabuf) { | 
					
						
							|  |  |  |             egl_dmabuf_create_fence(dmabuf); | 
					
						
							|  |  |  |             if (dmabuf->fence_fd > 0) { | 
					
						
							|  |  |  |                 qemu_set_fd_handler(dmabuf->fence_fd, gd_hw_gl_flushed, NULL, vc); | 
					
						
							|  |  |  |                 return; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             graphic_hw_gl_block(vc->gfx.dcl.con, false); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2015-05-08 11:30:51 +02:00
										 |  |  |     } else { | 
					
						
							|  |  |  |         if (!vc->gfx.ds) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         eglMakeCurrent(qemu_egl_display, vc->gfx.esurface, | 
					
						
							|  |  |  |                        vc->gfx.esurface, vc->gfx.ectx); | 
					
						
							| 
									
										
										
										
											2015-01-20 12:43:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-08 11:30:51 +02:00
										 |  |  |         surface_gl_setup_viewport(vc->gfx.gls, vc->gfx.ds, ww, wh); | 
					
						
							|  |  |  |         surface_gl_render_texture(vc->gfx.gls, vc->gfx.ds); | 
					
						
							| 
									
										
										
										
											2015-01-20 12:43:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-08 11:30:51 +02:00
										 |  |  |         eglSwapBuffers(qemu_egl_display, vc->gfx.esurface); | 
					
						
							| 
									
										
										
										
											2018-11-07 08:49:49 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         vc->gfx.scale_x = (double)ww / surface_width(vc->gfx.ds); | 
					
						
							|  |  |  |         vc->gfx.scale_y = (double)wh / surface_height(vc->gfx.ds); | 
					
						
							| 
									
										
										
										
											2021-09-14 14:18:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-24 15:51:05 -07:00
										 |  |  |         glFlush(); | 
					
						
							| 
									
										
										
										
											2021-09-14 14:18:35 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-01-20 12:43:28 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void gd_egl_update(DisplayChangeListener *dcl, | 
					
						
							|  |  |  |                    int x, int y, int w, int h) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!vc->gfx.gls || !vc->gfx.ds) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     eglMakeCurrent(qemu_egl_display, vc->gfx.esurface, | 
					
						
							|  |  |  |                    vc->gfx.esurface, vc->gfx.ectx); | 
					
						
							|  |  |  |     surface_gl_update_texture(vc->gfx.gls, vc->gfx.ds, x, y, w, h); | 
					
						
							|  |  |  |     vc->gfx.glupdates++; | 
					
						
							| 
									
										
										
										
											2023-06-28 12:15:04 -07:00
										 |  |  |     eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, | 
					
						
							|  |  |  |                    EGL_NO_SURFACE, EGL_NO_CONTEXT); | 
					
						
							| 
									
										
										
										
											2015-01-20 12:43:28 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void gd_egl_refresh(DisplayChangeListener *dcl) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-26 20:55:15 +09:00
										 |  |  |     gd_update_monitor_refresh_rate( | 
					
						
							|  |  |  |             vc, vc->window ? vc->window : vc->gfx.drawing_area); | 
					
						
							| 
									
										
										
										
											2021-01-14 15:01:53 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-06 11:33:55 -07:00
										 |  |  |     if (vc->gfx.guest_fb.dmabuf && vc->gfx.guest_fb.dmabuf->draw_submitted) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-20 12:43:28 +01:00
										 |  |  |     if (!vc->gfx.esurface) { | 
					
						
							|  |  |  |         gd_egl_init(vc); | 
					
						
							|  |  |  |         if (!vc->gfx.esurface) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-10-10 15:54:49 +02:00
										 |  |  |         vc->gfx.gls = qemu_gl_init_shader(); | 
					
						
							| 
									
										
										
										
											2015-01-20 12:43:28 +01:00
										 |  |  |         if (vc->gfx.ds) { | 
					
						
							| 
									
										
										
										
											2021-11-03 23:51:49 -07:00
										 |  |  |             surface_gl_destroy_texture(vc->gfx.gls, vc->gfx.ds); | 
					
						
							| 
									
										
										
										
											2015-01-20 12:43:28 +01:00
										 |  |  |             surface_gl_create_texture(vc->gfx.gls, vc->gfx.ds); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-11-08 09:31:29 +01:00
										 |  |  | #ifdef CONFIG_GBM
 | 
					
						
							| 
									
										
										
										
											2021-11-03 23:51:50 -07:00
										 |  |  |         if (vc->gfx.guest_fb.dmabuf) { | 
					
						
							|  |  |  |             egl_dmabuf_release_texture(vc->gfx.guest_fb.dmabuf); | 
					
						
							|  |  |  |             gd_egl_scanout_dmabuf(dcl, vc->gfx.guest_fb.dmabuf); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-11-08 09:31:29 +01:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2015-01-20 12:43:28 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     graphic_hw_update(dcl->con); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (vc->gfx.glupdates) { | 
					
						
							|  |  |  |         vc->gfx.glupdates = 0; | 
					
						
							| 
									
										
										
										
											2015-05-08 11:30:51 +02:00
										 |  |  |         gtk_egl_set_scanout_mode(vc, false); | 
					
						
							| 
									
										
										
										
											2015-01-20 12:43:28 +01:00
										 |  |  |         gd_egl_draw(vc); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void gd_egl_switch(DisplayChangeListener *dcl, | 
					
						
							|  |  |  |                    DisplaySurface *surface) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl); | 
					
						
							|  |  |  |     bool resized = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     trace_gd_switch(vc->label, surface_width(surface), surface_height(surface)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (vc->gfx.ds && | 
					
						
							|  |  |  |         surface_width(vc->gfx.ds) == surface_width(surface) && | 
					
						
							|  |  |  |         surface_height(vc->gfx.ds) == surface_height(surface)) { | 
					
						
							|  |  |  |         resized = false; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-11-03 23:51:49 -07:00
										 |  |  |     eglMakeCurrent(qemu_egl_display, vc->gfx.esurface, | 
					
						
							|  |  |  |                    vc->gfx.esurface, vc->gfx.ectx); | 
					
						
							| 
									
										
										
										
											2015-01-20 12:43:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     surface_gl_destroy_texture(vc->gfx.gls, vc->gfx.ds); | 
					
						
							|  |  |  |     vc->gfx.ds = surface; | 
					
						
							|  |  |  |     if (vc->gfx.gls) { | 
					
						
							|  |  |  |         surface_gl_create_texture(vc->gfx.gls, vc->gfx.ds); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (resized) { | 
					
						
							|  |  |  |         gd_update_windowsize(vc); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-09-28 14:58:05 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, | 
					
						
							|  |  |  |                    EGL_NO_CONTEXT); | 
					
						
							| 
									
										
										
										
											2015-01-20 12:43:28 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-09 23:48:46 +04:00
										 |  |  | QEMUGLContext gd_egl_create_context(DisplayGLCtx *dgc, | 
					
						
							| 
									
										
										
										
											2015-05-08 11:30:51 +02:00
										 |  |  |                                     QEMUGLParams *params) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-10-09 23:48:46 +04:00
										 |  |  |     VirtualConsole *vc = container_of(dgc, VirtualConsole, gfx.dgc); | 
					
						
							| 
									
										
										
										
											2015-05-08 11:30:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     eglMakeCurrent(qemu_egl_display, vc->gfx.esurface, | 
					
						
							|  |  |  |                    vc->gfx.esurface, vc->gfx.ectx); | 
					
						
							| 
									
										
										
										
											2021-10-09 23:48:46 +04:00
										 |  |  |     return qemu_egl_create_context(dgc, params); | 
					
						
							| 
									
										
										
										
											2015-05-08 11:30:51 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-21 10:37:21 +01:00
										 |  |  | void gd_egl_scanout_disable(DisplayChangeListener *dcl) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     vc->gfx.w = 0; | 
					
						
							|  |  |  |     vc->gfx.h = 0; | 
					
						
							|  |  |  |     gtk_egl_set_scanout_mode(vc, false); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-21 10:37:16 +01:00
										 |  |  | void gd_egl_scanout_texture(DisplayChangeListener *dcl, | 
					
						
							|  |  |  |                             uint32_t backing_id, bool backing_y_0_top, | 
					
						
							|  |  |  |                             uint32_t backing_width, uint32_t backing_height, | 
					
						
							|  |  |  |                             uint32_t x, uint32_t y, | 
					
						
							| 
									
										
										
										
											2023-06-06 15:56:56 +04:00
										 |  |  |                             uint32_t w, uint32_t h, | 
					
						
							|  |  |  |                             void *d3d_tex2d) | 
					
						
							| 
									
										
										
										
											2015-05-08 11:30:51 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     vc->gfx.x = x; | 
					
						
							|  |  |  |     vc->gfx.y = y; | 
					
						
							|  |  |  |     vc->gfx.w = w; | 
					
						
							|  |  |  |     vc->gfx.h = h; | 
					
						
							|  |  |  |     vc->gfx.y0_top = backing_y_0_top; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-16 14:32:15 +02:00
										 |  |  |     if (!vc->gfx.esurface) { | 
					
						
							|  |  |  |         gd_egl_init(vc); | 
					
						
							|  |  |  |         if (!vc->gfx.esurface) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-11-11 11:40:20 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 11:30:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-11 11:40:20 +01:00
										 |  |  |     eglMakeCurrent(qemu_egl_display, vc->gfx.esurface, | 
					
						
							|  |  |  |                    vc->gfx.esurface, vc->gfx.ectx); | 
					
						
							| 
									
										
										
										
											2023-10-16 14:32:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-11 11:40:20 +01:00
										 |  |  |     gtk_egl_set_scanout_mode(vc, true); | 
					
						
							|  |  |  |     egl_fb_setup_for_tex(&vc->gfx.guest_fb, backing_width, backing_height, | 
					
						
							|  |  |  |                          backing_id, false); | 
					
						
							| 
									
										
										
										
											2015-05-08 11:30:51 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-06 10:09:50 +01:00
										 |  |  | void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl, | 
					
						
							|  |  |  |                            QemuDmaBuf *dmabuf) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-02-23 15:03:07 +09:00
										 |  |  | #ifdef CONFIG_GBM
 | 
					
						
							| 
									
										
										
										
											2021-09-14 14:18:35 -07:00
										 |  |  |     VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-03 23:51:49 -07:00
										 |  |  |     eglMakeCurrent(qemu_egl_display, vc->gfx.esurface, | 
					
						
							|  |  |  |                    vc->gfx.esurface, vc->gfx.ectx); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-06 10:09:50 +01:00
										 |  |  |     egl_dmabuf_import_texture(dmabuf); | 
					
						
							|  |  |  |     if (!dmabuf->texture) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     gd_egl_scanout_texture(dcl, dmabuf->texture, | 
					
						
							| 
									
										
										
										
											2023-07-12 21:04:44 -07:00
										 |  |  |                            dmabuf->y0_top, | 
					
						
							|  |  |  |                            dmabuf->backing_width, dmabuf->backing_height, | 
					
						
							|  |  |  |                            dmabuf->x, dmabuf->y, dmabuf->width, | 
					
						
							|  |  |  |                            dmabuf->height, NULL); | 
					
						
							| 
									
										
										
										
											2021-09-14 14:18:35 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (dmabuf->allow_fences) { | 
					
						
							|  |  |  |         vc->gfx.guest_fb.dmabuf = dmabuf; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-03-06 10:09:50 +01:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-06 10:09:51 +01:00
										 |  |  | void gd_egl_cursor_dmabuf(DisplayChangeListener *dcl, | 
					
						
							|  |  |  |                           QemuDmaBuf *dmabuf, bool have_hot, | 
					
						
							|  |  |  |                           uint32_t hot_x, uint32_t hot_y) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-02-23 15:03:07 +09:00
										 |  |  | #ifdef CONFIG_GBM
 | 
					
						
							| 
									
										
										
										
											2018-03-06 10:09:51 +01:00
										 |  |  |     VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (dmabuf) { | 
					
						
							|  |  |  |         egl_dmabuf_import_texture(dmabuf); | 
					
						
							|  |  |  |         if (!dmabuf->texture) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-07-12 21:04:44 -07:00
										 |  |  |         egl_fb_setup_for_tex(&vc->gfx.cursor_fb, | 
					
						
							|  |  |  |                              dmabuf->backing_width, dmabuf->backing_height, | 
					
						
							| 
									
										
										
										
											2018-03-06 10:09:51 +01:00
										 |  |  |                              dmabuf->texture, false); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         egl_fb_destroy(&vc->gfx.cursor_fb); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void gd_egl_cursor_position(DisplayChangeListener *dcl, | 
					
						
							|  |  |  |                             uint32_t pos_x, uint32_t pos_y) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 08:49:49 +01:00
										 |  |  |     vc->gfx.cursor_x = pos_x * vc->gfx.scale_x; | 
					
						
							|  |  |  |     vc->gfx.cursor_y = pos_y * vc->gfx.scale_y; | 
					
						
							| 
									
										
										
										
											2018-03-06 10:09:51 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-08 11:30:51 +02:00
										 |  |  | void gd_egl_scanout_flush(DisplayChangeListener *dcl, | 
					
						
							|  |  |  |                           uint32_t x, uint32_t y, uint32_t w, uint32_t h) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl); | 
					
						
							|  |  |  |     GdkWindow *window; | 
					
						
							| 
									
										
										
										
											2023-10-12 15:26:43 -07:00
										 |  |  |     int ww, wh, ws; | 
					
						
							| 
									
										
										
										
											2015-05-08 11:30:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (!vc->gfx.scanout_mode) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-06-14 10:41:49 +02:00
										 |  |  |     if (!vc->gfx.guest_fb.framebuffer) { | 
					
						
							| 
									
										
										
										
											2015-05-08 11:30:51 +02:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     eglMakeCurrent(qemu_egl_display, vc->gfx.esurface, | 
					
						
							|  |  |  |                    vc->gfx.esurface, vc->gfx.ectx); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     window = gtk_widget_get_window(vc->gfx.drawing_area); | 
					
						
							| 
									
										
										
										
											2023-10-12 15:26:43 -07:00
										 |  |  |     ws = gdk_window_get_scale_factor(window); | 
					
						
							|  |  |  |     ww = gdk_window_get_width(window) * ws; | 
					
						
							|  |  |  |     wh = gdk_window_get_height(window) * ws; | 
					
						
							| 
									
										
										
										
											2017-06-14 10:41:49 +02:00
										 |  |  |     egl_fb_setup_default(&vc->gfx.win_fb, ww, wh); | 
					
						
							| 
									
										
										
										
											2018-03-06 10:09:51 +01:00
										 |  |  |     if (vc->gfx.cursor_fb.texture) { | 
					
						
							|  |  |  |         egl_texture_blit(vc->gfx.gls, &vc->gfx.win_fb, &vc->gfx.guest_fb, | 
					
						
							|  |  |  |                          vc->gfx.y0_top); | 
					
						
							|  |  |  |         egl_texture_blend(vc->gfx.gls, &vc->gfx.win_fb, &vc->gfx.cursor_fb, | 
					
						
							|  |  |  |                           vc->gfx.y0_top, | 
					
						
							| 
									
										
										
										
											2019-01-25 15:47:23 +08:00
										 |  |  |                           vc->gfx.cursor_x, vc->gfx.cursor_y, | 
					
						
							|  |  |  |                           vc->gfx.scale_x, vc->gfx.scale_y); | 
					
						
							| 
									
										
										
										
											2018-03-06 10:09:51 +01:00
										 |  |  |     } else { | 
					
						
							|  |  |  |         egl_fb_blit(&vc->gfx.win_fb, &vc->gfx.guest_fb, !vc->gfx.y0_top); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 11:30:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-14 14:18:35 -07:00
										 |  |  | #ifdef CONFIG_GBM
 | 
					
						
							|  |  |  |     if (vc->gfx.guest_fb.dmabuf) { | 
					
						
							|  |  |  |         egl_dmabuf_create_sync(vc->gfx.guest_fb.dmabuf); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-08 11:30:51 +02:00
										 |  |  |     eglSwapBuffers(qemu_egl_display, vc->gfx.esurface); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-14 14:18:36 -07:00
										 |  |  | void gd_egl_flush(DisplayChangeListener *dcl, | 
					
						
							|  |  |  |                   uint32_t x, uint32_t y, uint32_t w, uint32_t h) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl); | 
					
						
							|  |  |  |     GtkWidget *area = vc->gfx.drawing_area; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-21 12:23:15 -07:00
										 |  |  |     if (vc->gfx.guest_fb.dmabuf && !vc->gfx.guest_fb.dmabuf->draw_submitted) { | 
					
						
							| 
									
										
										
										
											2021-09-14 14:18:36 -07:00
										 |  |  |         graphic_hw_gl_block(vc->gfx.dcl.con, true); | 
					
						
							| 
									
										
										
										
											2021-09-24 15:51:05 -07:00
										 |  |  |         vc->gfx.guest_fb.dmabuf->draw_submitted = true; | 
					
						
							| 
									
										
										
										
											2023-07-06 11:33:54 -07:00
										 |  |  |         gtk_egl_set_scanout_mode(vc, true); | 
					
						
							| 
									
										
										
										
											2021-09-14 14:18:36 -07:00
										 |  |  |         gtk_widget_queue_draw_area(area, x, y, w, h); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     gd_egl_scanout_flush(&vc->gfx.dcl, x, y, w, h); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-18 13:21:41 +02:00
										 |  |  | void gtk_egl_init(DisplayGLMode mode) | 
					
						
							| 
									
										
										
										
											2015-01-20 12:43:28 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     GdkDisplay *gdk_display = gdk_display_get_default(); | 
					
						
							|  |  |  |     Display *x11_display = gdk_x11_display_get_xdisplay(gdk_display); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-18 13:21:41 +02:00
										 |  |  |     if (qemu_egl_init_dpy_x11(x11_display, mode) < 0) { | 
					
						
							| 
									
										
										
										
											2015-01-20 12:43:28 +01:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     display_opengl = 1; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-05-08 11:30:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-09 23:48:46 +04:00
										 |  |  | int gd_egl_make_current(DisplayGLCtx *dgc, | 
					
						
							| 
									
										
										
										
											2015-05-08 11:30:51 +02:00
										 |  |  |                         QEMUGLContext ctx) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-10-09 23:48:46 +04:00
										 |  |  |     VirtualConsole *vc = container_of(dgc, VirtualConsole, gfx.dgc); | 
					
						
							| 
									
										
										
										
											2015-05-08 11:30:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-06 15:56:39 +04:00
										 |  |  |     if (!eglMakeCurrent(qemu_egl_display, vc->gfx.esurface, | 
					
						
							|  |  |  |                         vc->gfx.esurface, ctx)) { | 
					
						
							|  |  |  |         error_report("egl: eglMakeCurrent failed: %s", qemu_egl_get_error_string()); | 
					
						
							|  |  |  |         return -1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 0; | 
					
						
							| 
									
										
										
										
											2015-05-08 11:30:51 +02:00
										 |  |  | } |