| 
									
										
										
										
											2015-05-26 12:26:21 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * GTK UI -- glarea opengl code. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Requires 3.16+ (GtkGLArea widget). | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 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"
 | 
					
						
							| 
									
										
										
										
											2015-05-26 12:26:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "trace.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "ui/console.h"
 | 
					
						
							|  |  |  | #include "ui/gtk.h"
 | 
					
						
							|  |  |  | #include "ui/egl-helpers.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "sysemu/sysemu.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void gtk_gl_area_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
										 |  |  |         gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area)); | 
					
						
							| 
									
										
										
										
											2017-06-14 10:41:49 +02:00
										 |  |  |         egl_fb_destroy(&vc->gfx.guest_fb); | 
					
						
							| 
									
										
										
										
											2015-05-26 12:26:21 +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); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** DisplayState Callbacks (opengl version) **/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void gd_gl_area_draw(VirtualConsole *vc) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-09-24 15:51:05 -07:00
										 |  |  | #ifdef CONFIG_GBM
 | 
					
						
							|  |  |  |     QemuDmaBuf *dmabuf = vc->gfx.guest_fb.dmabuf; | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2021-11-21 01:55:03 -05:00
										 |  |  |     int ww, wh, ws, y1, y2; | 
					
						
							| 
									
										
										
										
											2015-05-26 12:26:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (!vc->gfx.gls) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area)); | 
					
						
							| 
									
										
										
										
											2021-11-21 01:55:03 -05:00
										 |  |  |     ws = gdk_window_get_scale_factor(gtk_widget_get_window(vc->gfx.drawing_area)); | 
					
						
							|  |  |  |     ww = gtk_widget_get_allocated_width(vc->gfx.drawing_area) * ws; | 
					
						
							|  |  |  |     wh = gtk_widget_get_allocated_height(vc->gfx.drawing_area) * ws; | 
					
						
							| 
									
										
										
										
											2015-05-26 12:26:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (vc->gfx.scanout_mode) { | 
					
						
							| 
									
										
										
										
											2017-06-14 10:41:49 +02:00
										 |  |  |         if (!vc->gfx.guest_fb.framebuffer) { | 
					
						
							| 
									
										
										
										
											2015-05-26 12:26:21 +02:00
										 |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-24 15:51:05 -07:00
										 |  |  | #ifdef CONFIG_GBM
 | 
					
						
							|  |  |  |         if (dmabuf) { | 
					
						
							| 
									
										
										
										
											2024-05-08 10:54:00 -07:00
										 |  |  |             if (!qemu_dmabuf_get_draw_submitted(dmabuf)) { | 
					
						
							| 
									
										
										
										
											2021-09-24 15:51:05 -07:00
										 |  |  |                 return; | 
					
						
							|  |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2024-05-08 10:54:01 -07:00
										 |  |  |                 qemu_dmabuf_set_draw_submitted(dmabuf, false); | 
					
						
							| 
									
										
										
										
											2021-09-24 15:51:05 -07:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-14 10:41:49 +02:00
										 |  |  |         glBindFramebuffer(GL_READ_FRAMEBUFFER, vc->gfx.guest_fb.framebuffer); | 
					
						
							| 
									
										
										
										
											2015-05-26 12:26:21 +02:00
										 |  |  |         /* GtkGLArea sets GL_DRAW_FRAMEBUFFER for us */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         glViewport(0, 0, ww, wh); | 
					
						
							|  |  |  |         y1 = vc->gfx.y0_top ? 0 : vc->gfx.h; | 
					
						
							|  |  |  |         y2 = vc->gfx.y0_top ? vc->gfx.h : 0; | 
					
						
							|  |  |  |         glBlitFramebuffer(0, y1, vc->gfx.w, y2, | 
					
						
							|  |  |  |                           0, 0, ww, wh, | 
					
						
							|  |  |  |                           GL_COLOR_BUFFER_BIT, GL_NEAREST); | 
					
						
							| 
									
										
										
										
											2021-09-24 15:51:05 -07:00
										 |  |  | #ifdef CONFIG_GBM
 | 
					
						
							|  |  |  |         if (dmabuf) { | 
					
						
							|  |  |  |             egl_dmabuf_create_sync(dmabuf); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |         glFlush(); | 
					
						
							|  |  |  | #ifdef CONFIG_GBM
 | 
					
						
							|  |  |  |         if (dmabuf) { | 
					
						
							| 
									
										
										
										
											2024-05-08 10:54:00 -07:00
										 |  |  |             int fence_fd; | 
					
						
							| 
									
										
										
										
											2021-09-24 15:51:05 -07:00
										 |  |  |             egl_dmabuf_create_fence(dmabuf); | 
					
						
							| 
									
										
										
										
											2024-05-08 10:54:00 -07:00
										 |  |  |             fence_fd = qemu_dmabuf_get_fence_fd(dmabuf); | 
					
						
							|  |  |  |             if (fence_fd >= 0) { | 
					
						
							|  |  |  |                 qemu_set_fd_handler(fence_fd, gd_hw_gl_flushed, NULL, vc); | 
					
						
							| 
									
										
										
										
											2021-09-24 15:51:05 -07:00
										 |  |  |                 return; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             graphic_hw_gl_block(vc->gfx.dcl.con, false); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2015-05-26 12:26:21 +02:00
										 |  |  |     } else { | 
					
						
							|  |  |  |         if (!vc->gfx.ds) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         surface_gl_setup_viewport(vc->gfx.gls, vc->gfx.ds, ww, wh); | 
					
						
							|  |  |  |         surface_gl_render_texture(vc->gfx.gls, vc->gfx.ds); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void gd_gl_area_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; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area)); | 
					
						
							|  |  |  |     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
										 |  |  |     gdk_gl_context_clear_current(); | 
					
						
							| 
									
										
										
										
											2015-05-26 12:26:21 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void gd_gl_area_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-10-24 16:31:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-08 10:54:00 -07:00
										 |  |  |     if (vc->gfx.guest_fb.dmabuf && | 
					
						
							|  |  |  |         qemu_dmabuf_get_draw_submitted(vc->gfx.guest_fb.dmabuf)) { | 
					
						
							| 
									
										
										
										
											2024-04-26 15:50:59 -07:00
										 |  |  |         gd_gl_area_draw(vc); | 
					
						
							| 
									
										
										
										
											2023-07-06 11:33:55 -07:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-26 12:26:21 +02:00
										 |  |  |     if (!vc->gfx.gls) { | 
					
						
							|  |  |  |         if (!gtk_widget_get_realized(vc->gfx.drawing_area)) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area)); | 
					
						
							| 
									
										
										
										
											2017-10-10 15:54:49 +02:00
										 |  |  |         vc->gfx.gls = qemu_gl_init_shader(); | 
					
						
							| 
									
										
										
										
											2015-05-26 12:26:21 +02:00
										 |  |  |         if (vc->gfx.ds) { | 
					
						
							|  |  |  |             surface_gl_create_texture(vc->gfx.gls, vc->gfx.ds); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     graphic_hw_update(dcl->con); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (vc->gfx.glupdates) { | 
					
						
							|  |  |  |         vc->gfx.glupdates = 0; | 
					
						
							|  |  |  |         gtk_gl_area_set_scanout_mode(vc, false); | 
					
						
							|  |  |  |         gtk_gl_area_queue_render(GTK_GL_AREA(vc->gfx.drawing_area)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void gd_gl_area_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; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (vc->gfx.gls) { | 
					
						
							|  |  |  |         gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area)); | 
					
						
							|  |  |  |         surface_gl_destroy_texture(vc->gfx.gls, vc->gfx.ds); | 
					
						
							|  |  |  |         surface_gl_create_texture(vc->gfx.gls, surface); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     vc->gfx.ds = surface; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (resized) { | 
					
						
							|  |  |  |         gd_update_windowsize(vc); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-05 10:51:31 +02:00
										 |  |  | static int gd_cmp_gl_context_version(int major, int minor, QEMUGLParams *params) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (major > params->major_ver) { | 
					
						
							|  |  |  |         return 1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (major < params->major_ver) { | 
					
						
							|  |  |  |         return -1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (minor > params->minor_ver) { | 
					
						
							|  |  |  |         return 1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (minor < params->minor_ver) { | 
					
						
							|  |  |  |         return -1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-09 23:48:46 +04:00
										 |  |  | QEMUGLContext gd_gl_area_create_context(DisplayGLCtx *dgc, | 
					
						
							| 
									
										
										
										
											2015-05-26 12:26:21 +02:00
										 |  |  |                                         QEMUGLParams *params) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-10-09 23:48:46 +04:00
										 |  |  |     VirtualConsole *vc = container_of(dgc, VirtualConsole, gfx.dgc); | 
					
						
							| 
									
										
										
										
											2015-05-26 12:26:21 +02:00
										 |  |  |     GdkWindow *window; | 
					
						
							|  |  |  |     GdkGLContext *ctx; | 
					
						
							|  |  |  |     GError *err = NULL; | 
					
						
							| 
									
										
										
										
											2022-06-05 10:51:31 +02:00
										 |  |  |     int major, minor; | 
					
						
							| 
									
										
										
										
											2015-05-26 12:26:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     window = gtk_widget_get_window(vc->gfx.drawing_area); | 
					
						
							|  |  |  |     ctx = gdk_window_create_gl_context(window, &err); | 
					
						
							| 
									
										
										
										
											2020-08-31 09:43:10 -04:00
										 |  |  |     if (err) { | 
					
						
							|  |  |  |         g_printerr("Create gdk gl context failed: %s\n", err->message); | 
					
						
							|  |  |  |         g_error_free(err); | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-26 12:26:21 +02:00
										 |  |  |     gdk_gl_context_set_required_version(ctx, | 
					
						
							|  |  |  |                                         params->major_ver, | 
					
						
							|  |  |  |                                         params->minor_ver); | 
					
						
							|  |  |  |     gdk_gl_context_realize(ctx, &err); | 
					
						
							| 
									
										
										
										
											2020-08-31 09:43:10 -04:00
										 |  |  |     if (err) { | 
					
						
							|  |  |  |         g_printerr("Realize gdk gl context failed: %s\n", err->message); | 
					
						
							|  |  |  |         g_error_free(err); | 
					
						
							|  |  |  |         g_clear_object(&ctx); | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-06-05 10:51:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     gdk_gl_context_make_current(ctx); | 
					
						
							|  |  |  |     gdk_gl_context_get_version(ctx, &major, &minor); | 
					
						
							|  |  |  |     gdk_gl_context_clear_current(); | 
					
						
							|  |  |  |     gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (gd_cmp_gl_context_version(major, minor, params) == -1) { | 
					
						
							|  |  |  |         /* created ctx version < requested version */ | 
					
						
							|  |  |  |         g_clear_object(&ctx); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     trace_gd_gl_area_create_context(ctx, params->major_ver, params->minor_ver); | 
					
						
							| 
									
										
										
										
											2015-05-26 12:26:21 +02:00
										 |  |  |     return ctx; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-09 23:48:46 +04:00
										 |  |  | void gd_gl_area_destroy_context(DisplayGLCtx *dgc, QEMUGLContext ctx) | 
					
						
							| 
									
										
										
										
											2015-05-26 12:26:21 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-06-05 10:51:30 +02:00
										 |  |  |     GdkGLContext *current_ctx = gdk_gl_context_get_current(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     trace_gd_gl_area_destroy_context(ctx, current_ctx); | 
					
						
							|  |  |  |     if (ctx == current_ctx) { | 
					
						
							|  |  |  |         gdk_gl_context_clear_current(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     g_clear_object(&ctx); | 
					
						
							| 
									
										
										
										
											2015-05-26 12:26:21 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-21 10:37:16 +01:00
										 |  |  | void gd_gl_area_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-26 12:26:21 +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; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-02 14:40:52 +02:00
										 |  |  |     if (backing_id == 0 || vc->gfx.w == 0 || vc->gfx.h == 0) { | 
					
						
							| 
									
										
										
										
											2015-05-26 12:26:21 +02:00
										 |  |  |         gtk_gl_area_set_scanout_mode(vc, false); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-24 17:11:31 -07:00
										 |  |  |     gtk_gl_area_set_scanout_mode(vc, true); | 
					
						
							| 
									
										
										
										
											2017-09-27 13:50:31 +02:00
										 |  |  |     egl_fb_setup_for_tex(&vc->gfx.guest_fb, backing_width, backing_height, | 
					
						
							|  |  |  |                          backing_id, false); | 
					
						
							| 
									
										
										
										
											2015-05-26 12:26:21 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 14:52:19 +04:00
										 |  |  | void gd_gl_area_scanout_disable(DisplayChangeListener *dcl) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     gtk_gl_area_set_scanout_mode(vc, false); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-26 12:26:21 +02:00
										 |  |  | void gd_gl_area_scanout_flush(DisplayChangeListener *dcl, | 
					
						
							|  |  |  |                           uint32_t x, uint32_t y, uint32_t w, uint32_t h) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-08 10:54:00 -07:00
										 |  |  |     if (vc->gfx.guest_fb.dmabuf && | 
					
						
							|  |  |  |         !qemu_dmabuf_get_draw_submitted(vc->gfx.guest_fb.dmabuf)) { | 
					
						
							| 
									
										
										
										
											2021-09-14 14:18:35 -07:00
										 |  |  |         graphic_hw_gl_block(vc->gfx.dcl.con, true); | 
					
						
							| 
									
										
										
										
											2024-05-08 10:54:01 -07:00
										 |  |  |         qemu_dmabuf_set_draw_submitted(vc->gfx.guest_fb.dmabuf, true); | 
					
						
							| 
									
										
										
										
											2023-07-06 11:33:54 -07:00
										 |  |  |         gtk_gl_area_set_scanout_mode(vc, true); | 
					
						
							| 
									
										
										
										
											2021-09-14 14:18:35 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-26 12:26:21 +02:00
										 |  |  |     gtk_gl_area_queue_render(GTK_GL_AREA(vc->gfx.drawing_area)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 14:52:28 +04:00
										 |  |  | void gd_gl_area_scanout_dmabuf(DisplayChangeListener *dcl, | 
					
						
							|  |  |  |                                QemuDmaBuf *dmabuf) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-02-23 15:03:07 +09:00
										 |  |  | #ifdef CONFIG_GBM
 | 
					
						
							| 
									
										
										
										
											2021-02-04 14:52:28 +04:00
										 |  |  |     VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl); | 
					
						
							| 
									
										
										
										
											2024-05-08 10:54:00 -07:00
										 |  |  |     uint32_t x, y, width, height, backing_width, backing_height, texture; | 
					
						
							|  |  |  |     bool y0_top; | 
					
						
							| 
									
										
										
										
											2021-02-04 14:52:28 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area)); | 
					
						
							|  |  |  |     egl_dmabuf_import_texture(dmabuf); | 
					
						
							| 
									
										
										
										
											2024-05-08 10:54:00 -07:00
										 |  |  |     texture = qemu_dmabuf_get_texture(dmabuf); | 
					
						
							|  |  |  |     if (!texture) { | 
					
						
							| 
									
										
										
										
											2021-02-04 14:52:28 +04:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-08 10:54:00 -07:00
										 |  |  |     x = qemu_dmabuf_get_x(dmabuf); | 
					
						
							|  |  |  |     y = qemu_dmabuf_get_y(dmabuf); | 
					
						
							|  |  |  |     width = qemu_dmabuf_get_width(dmabuf); | 
					
						
							|  |  |  |     height = qemu_dmabuf_get_height(dmabuf); | 
					
						
							|  |  |  |     backing_width = qemu_dmabuf_get_backing_width(dmabuf); | 
					
						
							|  |  |  |     backing_height = qemu_dmabuf_get_backing_height(dmabuf); | 
					
						
							|  |  |  |     y0_top = qemu_dmabuf_get_y0_top(dmabuf); | 
					
						
							| 
									
										
										
										
											2021-09-14 14:18:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-08 10:54:00 -07:00
										 |  |  |     gd_gl_area_scanout_texture(dcl, texture, y0_top, | 
					
						
							|  |  |  |                                backing_width, backing_height, | 
					
						
							|  |  |  |                                x, y, width, height, NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (qemu_dmabuf_get_allow_fences(dmabuf)) { | 
					
						
							| 
									
										
										
										
											2021-09-14 14:18:35 -07:00
										 |  |  |         vc->gfx.guest_fb.dmabuf = dmabuf; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-02-04 14:52:28 +04:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-26 12:26:21 +02:00
										 |  |  | void gtk_gl_area_init(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     display_opengl = 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-09 23:48:46 +04:00
										 |  |  | int gd_gl_area_make_current(DisplayGLCtx *dgc, | 
					
						
							| 
									
										
										
										
											2015-05-26 12:26:21 +02:00
										 |  |  |                             QEMUGLContext ctx) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     gdk_gl_context_make_current(ctx); | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  | } |