ui: Enable SDL to use dma-buf for direct guest framebuffer rendering
RFC PATCH 1/1 ui: Enable SDL to use dma-buf for direct guest framebuffer rendering
This RFC patch is based on Qemu UI on-going work of rendering guest framebuffer through dma-buf interface, to show a protype of SDL with dma-buf interface.
Against branch: work/intel-vgpu
--- include/ui/sdl2.h | 11 ++++++++ ui/sdl2-gl.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++--------- ui/sdl2.c | 6 ++-- 3 files changed, 86 insertions(+), 15 deletions(-)
include/ui/sdl2.h +11 -0
@@ -29,6 +29,9 @@ struct sdl2_console {QemuGLShader *gls;egl_fb guest_fb;egl_fb win_fb; +egl_fb cursor_fb; +int cursor_x; +int cursor_y;bool y0_top;bool scanout_mode;#endif
@@ -76,6 +79,14 @@ void sdl2_gl_scanout_texture(DisplayChangeListener *dcl, uint32_t w, uint32_t h);void sdl2_gl_scanout_dmabuf (DisplayChangeListener *dcl,QemuDmaBuf *dmabuf); +void sdl2_gl_cursor_dmabuf (DisplayChangeListener *dcl, +QemuDmaBuf *dmabuf); +void sdl2_gl_cursor_position (DisplayChangeListener *dcl, +bool have_hot,bool have_pos, +uint32_t hot_x,uint32_t hot_y, +uint32_t pos_x,uint32_t pos_y); +void sdl2_gl_release_dmabuf (DisplayChangeListener *dcl, +QemuDmaBuf *dmabuf);void sdl2_gl_scanout_flush (DisplayChangeListener *dcl,uint32_t x,uint32_t y,uint32_t w,uint32_t h);
ui/sdl2-gl.c +71 -13
132 lines not on this page · raw message
ui/sdl2.c +4 -2
@@ -84,7 +84,6 @@ void sdl2_window_create(struct sdl2_console *scon)if (scon->hidden) { flags |=SDL_WINDOW_HIDDEN ; } - scon->real_window = SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, surface_width(scon->surface),
@@ -118,7 +117,6 @@ void sdl2_window_resize(struct sdl2_console *scon)if (!scon->real_window) {return ; } -SDL_SetWindowSize (scon->real_window,surface_width (scon->surface),surface_height (scon->surface));
@@ -740,6 +738,9 @@ static const DisplayChangeListenerOps dcl_gl_ops = { .dpy_gl_scanout_disable = sdl2_gl_scanout_disable, .dpy_gl_scanout_texture = sdl2_gl_scanout_texture, .dpy_gl_scanout_dmabuf = sdl2_gl_scanout_dmabuf, + .dpy_gl_cursor_dmabuf = sdl2_gl_cursor_dmabuf, + .dpy_gl_cursor_position = sdl2_gl_cursor_position, + .dpy_gl_release_dmabuf = sdl2_gl_release_dmabuf, .dpy_gl_update = sdl2_gl_scanout_flush, };#endif
@@ -835,6 +836,7 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)#endif } +qemu_egl_init_dpy_x11 (info.info.x11.display);/* Load a 32x32x4 image. White pixels are transparent. */ filename =qemu_find_file (QEMU_FILE_TYPE_BIOS ,"qemu-icon.bmp" );if (filename) {
Signature · 1 line
2.7.4
This patch is using SDL_GL_GetCurrentContext() to get a context and meet an issue with SDL_GL_CONTEXT_EGL which is deprecated since SDL 2.1.
Before SDL 2.1, SDL_GL_CONTEXT_EGL can be used with SDL_GL_SetAttribute, so that an EGLContext can be created with SDL_GL_GetCurrentContext(). Since SDL_GL_CONTEXT_EGL is deprecated now, is there a way to let SDL_GL_GetCurrentContext() return an EGLContext? Thanks.
BR,
Tina
Quoted 230 lines
-----Original Message-----
From: Zhang, Tina
Sent: Friday, December 8, 2017 5:33 PM
To: [email protected]; [email protected]
Cc: Zhang, Tina <[email protected]>; [email protected]; intel-gvt- [email protected]; Wang, Zhi A <[email protected]>; Yuan, Hang <[email protected]>; Lv, Zhiyuan <[email protected]>
Subject: [Rfc PATCH] ui: Enable SDL to use dma-buf for direct guest framebuffer renderingThis RFC patch is based on Qemu UI on-going work of rendering guest framebuffer through dma-buf interface, to show a protype of SDL with dma-buf interface.
Against branch: work/intel-vgpu
Signed-off-by Tina Zhang <[email protected]>--- include/ui/sdl2.h | 11 ++++++++ ui/sdl2-gl.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++--------- ui/sdl2.c | 6 ++-- 3 files changed, 86 insertions(+), 15 deletions(-)include/ui/sdl2.h index 7811d33..e6e334c renamed from include/ui/sdl2.h +0
-0100644
include/ui/sdl2.h +11
-0@@ -29,6 +29,9 @@ struct sdl2_console {QemuGLShader *gls;egl_fb guest_fb;egl_fb win_fb; +egl_fb cursor_fb; +int cursor_x; +int cursor_y;bool y0_top;bool scanout_mode;#endif @@ -76,6 +79,14 @@ void sdl2_gl_scanout_texture(DisplayChangeListener *dcl, uint32_t w, uint32_t h); voidsdl2_gl_scanout_dmabuf (DisplayChangeListener *dcl,QemuDmaBuf *dmabuf); +void sdl2_gl_cursor_dmabuf (DisplayChangeListener *dcl, +QemuDmaBuf *dmabuf);void +sdl2_gl_cursor_position (DisplayChangeListener *dcl, +bool have_hot,bool have_pos, +uint32_t hot_x,uint32_t hot_y, +uint32_t pos_x,uint32_t pos_y);void +sdl2_gl_release_dmabuf (DisplayChangeListener *dcl, +QemuDmaBuf *dmabuf);void sdl2_gl_scanout_flush (DisplayChangeListener *dcl,uint32_t x,uint32_t y,uint32_t w,uint32_t h);ui/sdl2-gl.c +6
-3@@ -72,9 +72,12 @@ void sdl2_gl_update(DisplayChangeListener *dcl,assert (scon->opengl); -SDL_GL_MakeCurrent (scon->real_window, scon->winctx); -surface_gl_update_texture (scon->gls, scon->surface, x, y, w, h); - scon->updates++; +if (!scon->scanout_mode) { +/* Fixme: unmarking these leads to flashing issue */ +//SDL_GL_MakeCurrent(scon->real_window, scon->winctx); +surface_gl_update_texture (scon->gls, scon->surface, x, y, w, h); +//scon->updates++; + } } void sdl2_gl_switch(DisplayChangeListener *dcl, @@ -116,7 +119,7 @@ void
sdl2_gl_refresh(DisplayChangeListener *dcl)assert(scon->opengl); graphic_hw_update(dcl->con);ui/sdl2-gl.c +62
-10-if (scon->updates && scon->surface) { +if (!scon->scanout_mode && scon->updates && scon->surface) { scon->updates =0 ;sdl2_gl_render_surface (scon); }@@ -127,8 +130,12 @@ void sdl2_gl_redraw(struct sdl2_console *scon) {assert (scon->opengl); -if (scon->surface) { -sdl2_gl_render_surface (scon); +if (scon->scanout_mode) { +sdl2_gl_scanout_flush (&scon->dcl,0 ,0 ,0 ,0 ); + }else { +if (scon->surface) { +sdl2_gl_render_surface (scon); + } } }@@ -208,22 +215,64 @@ void sdl2_gl_scanout_texture(DisplayChangeListener *dcl, SDL_GL_MakeCurrent(scon->real_window, scon->winctx); sdl2_set_scanout_mode(scon, true); + egl_fb_setup_for_tex(&scon->guest_fb, backing_width, backing_height, backing_id, false); } + void sdl2_gl_scanout_dmabuf(DisplayChangeListener *dcl, QemuDmaBuf *dmabuf) { - struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl); -int tex_id =0 ; +#ifdef CONFIG_OPENGL_DMABUF + + egl_dmabuf_import_texture(dmabuf); -/* TODO: import dmabuf */ + if (!dmabuf->texture) { + return; + } -sdl2_gl_scanout_texture (dcl, tex_id, + sdl2_gl_scanout_texture(dcl, dmabuf->texture, false, dmabuf->width, dmabuf->height, 0, 0, dmabuf->width, dmabuf->height); - scon->guest_fb.delete_texture = true; +#endif +} + +void sdl2_gl_cursor_dmabuf(DisplayChangeListener *dcl, + QemuDmaBuf *dmabuf) { #ifdef +CONFIG_OPENGL_DMABUF + struct sdl2_console *scon = container_of(dcl, struct sdl2_console, +dcl); + + egl_dmabuf_import_texture(dmabuf); + if (!dmabuf->texture) { + return; + } + + egl_fb_setup_for_tex(&scon->cursor_fb, dmabuf->width, dmabuf->height, + dmabuf->texture, false); #endif } + +void sdl2_gl_cursor_position(DisplayChangeListener *dcl, + bool have_hot, bool have_pos, + uint32_t hot_x, uint32_t hot_y, + uint32_t pos_x, uint32_t pos_y) { #ifdef +CONFIG_OPENGL_DMABUF + struct sdl2_console *scon = container_of(dcl, struct sdl2_console, +dcl); + + scon->cursor_x = pos_x; + scon->cursor_y = pos_y; +#endif +} + +void sdl2_gl_release_dmabuf(DisplayChangeListener *dcl, + QemuDmaBuf *dmabuf) { #ifdef +CONFIG_OPENGL_DMABUF + egl_dmabuf_release_texture(dmabuf); +#endif } void sdl2_gl_scanout_flush(DisplayChangeListener *dcl, @@ -236,15 +285,24 @@ void sdl2_gl_scanout_flush(DisplayChangeListener *dcl, if (!scon->scanout_mode) { return; } + if (!scon->guest_fb.framebuffer) { return; } SDL_GL_MakeCurrent(scon->real_window, scon->winctx); - SDL_GetWindowSize(scon->real_window, &ww, &wh); + egl_fb_setup_default(&scon->win_fb, ww, wh); -egl_fb_blit (&scon->win_fb, &scon->guest_fb, !scon->y0_top); + if (scon->cursor_fb.texture) { + egl_texture_blit(scon->gls, &scon->win_fb, &scon->guest_fb, + scon->y0_top); + egl_texture_blend(scon->gls, &scon->win_fb, &scon->cursor_fb, + scon->y0_top, + scon->cursor_x, scon->cursor_y); + } else { + egl_fb_blit(&scon->win_fb, &scon->guest_fb, !scon->y0_top); + } SDL_GL_SwapWindow(scon->real_window); }ui/sdl2.c +0
-1@@ -84,7 +84,6 @@ void sdl2_window_create(struct sdl2_console *scon)if (scon->hidden) { flags |=SDL_WINDOW_HIDDEN ; } - scon->real_window = SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,surface_width(scon->surface), @@ -118,7 +117,6 @@ void sdl2_window_resize(struct sdl2_console *scon) if (!scon->real_window) { return; } - SDL_SetWindowSize(scon->real_window, surface_width(scon->surface), surface_height(scon->surface)); @@ -740,6 +738,9 @@ static const DisplayChangeListenerOps dcl_gl_ops = { .dpy_gl_scanout_disable = sdl2_gl_scanout_disable, .dpy_gl_scanout_texture = sdl2_gl_scanout_texture, .dpy_gl_scanout_dmabuf = sdl2_gl_scanout_dmabuf,ui/sdl2.c +3
-0+ .dpy_gl_cursor_dmabuf = sdl2_gl_cursor_dmabuf, + .dpy_gl_cursor_position = sdl2_gl_cursor_position, + .dpy_gl_release_dmabuf = sdl2_gl_release_dmabuf, .dpy_gl_update = sdl2_gl_scanout_flush, };#endif @@ -835,6 +836,7 @@ void sdl_display_init(DisplayState *ds, int full_screen,int
no_frame) #endif}+ qemu_egl_init_dpy_x11(info.info.x11.display); /* Load a 32x32x4 image. White pixels are transparent. */ filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, "qemu-icon.bmp"); if (filename) {--
2.7.4